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

Jeroen van der Zijp jeroen at fox-toolkit.org
Mon May 15 23:11:56 EDT 2006


On Monday 15 May 2006 20:45, Lyle Johnson wrote:
> 
> 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)
> >       end
> >       puts " first = #{first}    last = #{last}"
> >
> >  
> >        Result:  last ==  8   !!!!!!   ===> problem , 8 is not selected


Think of the positions as being in between the characters; a position
is selected if it is inside the interval [min(anchor,cursor) .. max(anchor,cursor)]
and note that this includes the border of the interval, in other words, not
<min(anchor,cursor) .. max(anchor,cursor)>.

Why is this so? When you select a single character, the interval comprises
the position before and after the character.  Thus the length is 1, and
this can be clearly distinguished from an empty selection which would be
length 0.  

Note that designating the positions between the characters is quite natural
since the cursor goes only between the charactars.




		- Jeroen

-- 
+----------------------------------------------------------------------------+
| Copyright (C) 22:00 05/15/2006 Jeroen van der Zijp.   All Rights Reserved. |
+----------------------------------------------------------------------------+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/fxruby-users/attachments/20060515/18188883/attachment-0001.bin 


More information about the fxruby-users mailing list