[Gambas-user] difference between QT TextEdit.Select and TextArea.Select

Jaap Cramer jaap_cramer at ...67...
Thu Jan 17 21:22:22 CET 2008


HI

I discovered a inconvenient difference between the behavior of Method SELECT in TextEdit and TextArea. By a TextArea properties like POS can be used in the method SELECT. If the text contains Unicode the value of the cursor-position can be recalculated to the position in the string. This is not the case in TextEdit. Because TextEdit contains HTML-tags, the cursor position cannot be used, or recalculated to a position in the string.
Is this an error in TextEdit.Select; I want to select text, not positions...

I added a example snippet to illustrate. The following code is called on tBible_MouseUp(). If one changed the position of the cursor, the purpose is to select the word on a single click. The following snippet works fine if tBible is a TextArea. I want to add some markups, so I decided to change tBible into a TextEdit. 

  DIM iPos, iStart, iEnd AS Integer
  DIM sB AS String                 ' a temp container for the contents of tBible.text
  
  sB = tBible.Text & " "            'end of text and space, so each word is surrounded by spaces
  sB = Replace(sB, "\n", " ")    'consider a return as a space
  sB = Replace(sB, "־", " ")      'consider 'maqqef' (the high division-marker) as space

  IF tBible.Selection.Length = 0 THEN           'if there is already a selection, then don't change it!
    iPos = tBible.Pos                                    'Position of the CURSOR, not string, so I don't need to recalculate it from a unicode string
    iStart = String.RInStr(sB, " ", iPos)          'working with unicode, so recalculate values
    iEnd = String.InStr(sB, " ", iPos) - 1
    tBible.Select(iStart, iEnd - iStart)
  ENDIF 


grt
Jaap

Ubuntu 7.10, Gambas 2.0.0
_________________________________________________________________
Probeer Live Search: de zoekmachine van de makers van MSN! 
http://www.live.com/?searchOnly=true




More information about the User mailing list