Page 1 of 1

Scintilla search text without move cursor [Resolved]

Posted: Mon Jan 05, 2026 10:11 pm
by Kwai chang caine
Hello at all

Is it possible to search a text, without see the cursor move
Because with this method i see the cursor

Code: Select all

 ScintillaSendMessage(SciID, #SCI_SETANCHOR, StartSearch)
 ScintillaSendMessage(SciID, #SCI_SEARCHANCHOR)
 Start= ScintillaSendMessage(SciID, #SCI_SEARCHNEXT, 0, @Search)
 
Furthermore, i have try with this method but i only find the first item :|

Code: Select all

Procedure ScintillaCallBack(Gadget, *scinotify.SCNotification)
EndProcedure

OpenWindow(0, 0, 0, 320, 240, "Scintilla", #PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
ScintillaGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), @ScintillaCallBack())
ScintillaSendMessage(0, #SCI_SETMARGINTYPEN, 1, #SC_MARGIN_NUMBER)

; Set example text (PB 5.50 or newer)
*UTF8 = UTF8("sum = this.value + 5 + value + blabl VALUE sdfgdgdf vaLue;")
ScintillaSendMessage(0, #SCI_SETTEXT, 0, *UTF8)
FreeMemory(*UTF8)
#StyleBleu = 1

Procedure SearchText(SciID, Search.s, StartSearch)

 LgText = ScintillaSendMessage(SciID, #SCI_GETLENGTH)
 ScintillaSendMessage(SciID, #SCI_SETTARGETSTART, StartSearch)
 ScintillaSendMessage(SciID, #SCI_SETTARGETEND, LgText)
 Start = ScintillaSendMessage(SciID, #SCI_SEARCHNEXT, 0, @Search)
 
 ProcedureReturn Start
 
EndProcedure

Text$ = "value"

For i = 1 To 3
 Position = SearchText(0, Text$, Position)
 Debug Position
 Position + 1
Next 

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Have a good day

Re: Scintilla search text without move cursor

Posted: Tue Jan 06, 2026 12:03 am
by Mindphazer
Hi KCC
Something like this ?

Code: Select all

Procedure ScintillaCallBack(Gadget, *scinotify.SCNotification)
EndProcedure

OpenWindow(0, 0, 0, 640, 240, "Scintilla", #PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
ScintillaGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), @ScintillaCallBack())
ScintillaSendMessage(0, #SCI_SETMARGINTYPEN, 1, #SC_MARGIN_NUMBER)

; Set example text (PB 5.50 or newer)
*UTF8 = UTF8("sum = this.value + 5 + value + blabl VALUE sdfgdgdf vaLue;")
ScintillaSendMessage(0, #SCI_SETTEXT, 0, *UTF8)
FreeMemory(*UTF8)
#StyleBleu = 1


Procedure SearchText(SciID, Search.s)
  LgText = ScintillaSendMessage(SciID, #SCI_GETLENGTH)
  byteLen = StringByteLength(search, #PB_UTF8)
  *mem = AllocateMemory(byteLen + 1)
  PokeS(*mem, search, -1, #PB_UTF8)
  pos = ScintillaSendMessage(SciID, #SCI_GETSELECTIONEND)
  ScintillaSendMessage(SciID, #SCI_SETTARGETSTART, pos)
  ScintillaSendMessage(SciID, #SCI_SETTARGETEND, LgText)
  result = ScintillaSendMessage(SciID, #SCI_SEARCHINTARGET, byteLen, *mem)
  If result <> -1
     ScintillaSendMessage(SciID, #SCI_SETSEL, ScintillaSendMessage(SciID, #SCI_GETTARGETSTART), ScintillaSendMessage(SciID, #SCI_GETTARGETEND))
  EndIf
 ProcedureReturn result
 
EndProcedure

Text$ = "value"

Repeat
  Position = SearchText(0, Text$)
  Debug position
Until Position = -1

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: Scintilla search text without move cursor

Posted: Tue Jan 06, 2026 8:39 am
by Kwai chang caine
Thanks a lot Mindphazer 8)
Unfortunately today i can't test your nice code :| i'm not behind my pc
I'm pressed to be tomorrow for test it, and inform you of the result
Again thanks, at tomorrow and have a good day 8)

Re: Scintilla search text without move cursor

Posted: Tue Jan 06, 2026 6:32 pm
by Kwai chang caine
Hello Mindphazer

Like promises, i was able to get away earlier than expected, so I jumped on my PC to try your code. :D
Not only is it exactly what I wanted, but even more! :shock:
Thanks to you, I adapted it to be exactly what I was looking for. 8)

Code: Select all

Procedure ScintillaCallBack(Gadget, *scinotify.SCNotification)
EndProcedure

OpenWindow(0, 0, 0, 640, 240, "Scintilla", #PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
ScintillaGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), @ScintillaCallBack())
ScintillaSendMessage(0, #SCI_SETMARGINTYPEN, 1, #SC_MARGIN_NUMBER)

; Set example text (PB 5.50 or newer)
*UTF8 = UTF8("sum = this.value + 5 + value + blabl VALUE sdfgdgdf vaLue;")
ScintillaSendMessage(0, #SCI_SETTEXT, 0, *UTF8)
FreeMemory(*UTF8)

Procedure SearchText(SciID, Search.s, Position)

  LgText = ScintillaSendMessage(SciID, #SCI_GETLENGTH)
  *mem = UTF8(Search)
  ScintillaSendMessage(SciID, #SCI_SETTARGETSTART, Position)
  ScintillaSendMessage(SciID, #SCI_SETTARGETEND, LgText)
  result = ScintillaSendMessage(SciID, #SCI_SEARCHINTARGET, MemoryStringLength(*mem, #PB_UTF8|#PB_ByteLength), *mem)
  FreeMemory(*mem)
  ProcedureReturn result
 
EndProcedure

Debug SearchText(0, "value", 12)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
One thousand of thanks, for you precious help
Have a very good end of day 8)

Re: Scintilla search text without move cursor [Resolved]

Posted: Tue Jan 06, 2026 11:58 pm
by Mindphazer
Hi KCC
Glad I could help