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

Jaap Cramer jaap_cramer at ...67...
Fri Jan 18 13:59:28 CET 2008


Hi

I found a workaround for this problem. (I have troubles with the mailinglist, couldn't find back the message below, maybe it dint come trough, hope don't make a mess of it...). 
I use the following function to recalculate the StringPos in the RichText-string (s as string) from given CursorPosition.


PUBLIC FUNCTION iTags(s AS String, CursorPos AS Integer) AS Integer
  DIM i, q AS Integer
  DIM c AS Boolean
  
  i = 1
  q = 0
  
  DO 
  INC q
    IF string.Mid(s, q, 1) = "<" THEN c = TRUE
    IF c THEN INC i
    IF string.Mid(s, q, 1) = ">" THEN c = FALSE
  LOOP UNTIL i = q - CursorPos OR q = string.Len(s)
  
  RETURN i
END


----------------------------------------
> From: jaap_cramer at ...67...
> To: gambas-user at lists.sourceforge.net
> Subject: difference between QT TextEdit.Select and TextArea.Select
> Date: Thu, 17 Jan 2008 21:22:22 +0100
> 
> 
> 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

_________________________________________________________________
De mooiste afbeeldingen van Angelina Jolie vind je met Live Search
http://search.live.com/images/results.aspx?q=angelina%20jolie&FORM=MIINTM




More information about the User mailing list