[fxruby-users] FXTextField - posSelected?(pos)

Gérard Ménochet gerard.menochet at wanadoo.fr
Tue May 16 06:56:04 EDT 2006

Hi Jeroen, Lyle

       A gret thanks for your answers. My thoughts is that I had a bad reading of posSelected?(pos). I read "position selected" and understood "character selected"...... Ooops 

No problem to get the first and last characters of the selection except that using the posSelected? function for this goal is a bad idea and eventually a blind alley.

A solution : 

 first = atext.anchorPos < atext.cursorPos ?  atext.anchorPos : atext.cursorPos 
 last = (atext.anchorPos > atext.cursorPos ?  atext.anchorPos : atext.cursorPos) - 1
 noSelection =  first > last    


Gérard Ménochet

  ----- Original Message ----- 
  From: Lyle Johnson 
  To: Gérard Ménochet 
  Cc: fxruby-users at rubyforge.org 
  Sent: Tuesday, May 16, 2006 3:45 AM
  Subject: Re: [fxruby-users] FXTextField - posSelected?(pos)

  On May 15, 2006, at 3:21 PM, Gérard Ménochet wrote:

        On a FXtextField, I want to detect the low and high pos of the selected string
        example: the text is:  0123456789
        The selected string is :    234567
         first = last = -1
          atext.text.length.times  do |pos|
               first = pos  if atext.posSelected?(pos) and first < 0
               last = pos  if atext.posSelected?(pos)
          puts " first = #{first}    last = #{last}"

           Result:  last ==  8   !!!!!!   ===> problem , 8 is not selected

  I don't know a lot about this function, but am looking at the FOX source code for it. Tell me, what do cursorPos and anchorPos return in this scenario?

  atext.length.times do |pos|
  first = ...
  last = ...
  puts "first ..."
  puts "cursorPos = #{atext.cursorPos}"
  puts "anchorPos = #{atext.anchorPos}"


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/fxruby-users/attachments/20060516/7dbfddd9/attachment.htm 

More information about the fxruby-users mailing list