Hi, I wonder if am facing a bug or something else 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 More, atext.posSeltected?(last) ? true : false ===> true. In fact, it''s not selected If I try with 456789 (including the last character), it is ok ..... Some clues ? Regards G?rard M?nochet -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/fxruby-users/attachments/20060515/ca94dbc2/attachment.htm
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 selectedI 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 = ... end puts "first ..." puts "cursorPos = #{atext.cursorPos}" puts "anchorPos = #{atext.anchorPos}" Thanks, Lyle -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: text/enriched Size: 1544 bytes Desc: not available Url : http://rubyforge.org/pipermail/fxruby-users/attachments/20060515/3893bf73/attachment.bin
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 selectedThink 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
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 .... Regards 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) end 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 = ... end puts "first ..." puts "cursorPos = #{atext.cursorPos}" puts "anchorPos = #{atext.anchorPos}" Thanks, Lyle -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/fxruby-users/attachments/20060516/7dbfddd9/attachment.htm