Page 1 of 1

Scintilla / GoScintilla - Get Hover Word

Posted: Mon Feb 01, 2010 9:59 am
by Innesoft
I wrote an extra function for GoScintilla by Stephen Rodriguez (srod) and thought I'd share it since it's quite useful.
Just stick it into GoScintilla.pbi to use it.

Returns the word currently hovered over by the cursor, which can be used for F1-> contextual help, or whatever. If you're writing an IDE, this can be used to get help on commands.

Usage:
word$ = GOSCI_GetHoverText(id)

Code: Select all

;/////////////////////////////////////////////////////////////////////////////////
;The following function returns the word currently under the cursor.
Procedure.s GOSCI_GetHoverText(id)
  Protected text$
  If IsGadget(id) And GadgetType(id) = #PB_GadgetType_Scintilla
    curPos = ScintillaSendMessage(id, #SCI_GETCURRENTPOS)
    linePos = ScintillaSendMessage(id, #SCI_LINEFROMPOSITION,curPos)
    colPos = ScintillaSendMessage(id, #SCI_GETCOLUMN,curPos)
    
    text$=GOSCI_GetLineText(id, linePos)
    word$=""
    ;get the start of the word
    colPos=colPos+1
    stPos.i=1
    nonalpha.i=0
    For a.i=colPos To 1 Step-1
      m.c=Asc(Mid(text$,a.i,1))
      Select m.c
        Case 'a' To 'z', 'A' To 'Z'
          If nonalpha.i=0
            stPos.i=a.i
          EndIf
        Default
          nonalpha.i=1
      EndSelect
    Next
    ;get word
    For a.i=stPos.i To Len(text$)
      m.c=Asc(Mid(text$,a.i,1))
      Select m.c
        Case 'a' To 'z', 'A' To 'Z'
          word$=word$+Chr(m.c)
        Default
          If Trim(word$)<>""
            ProcedureReturn word$
          EndIf
      EndSelect
    Next
  EndIf
  ProcedureReturn word$
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////

Re: Scintilla / GoScintilla - Get Hover Word

Posted: Tue Mar 12, 2013 2:41 am
by Tenaja
This is a little quicker way to do it, and it uses the Gosci settings for what defines a "word". I just used it for putting text into the clipboard, but you can easily modify the last line if you need it in a string.

Code: Select all

			pos = SCI_GetCurrentPos(ActiveSci)
			WordStart = SCI_WordStartPosition(ActiveSci, pos, #True) ;bool onlyWordCharacters)
			WordEnd = SCI_WordEndPosition(ActiveSci, pos,#True); bool onlyWordCharacters)
; To put it in the clipboard:
			SendSci(ActiveSci, #SCI_COPYRANGE, WordStart, WordEnd) 
; To put it in a string, convert this to pb:
; SCI_GETTEXTRANGE(<unused>, Sci_TextRange *tr)