Scintilla search text without move cursor [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5614
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Scintilla search text without move cursor [Resolved]

Post 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
Last edited by Kwai chang caine on Tue Jan 06, 2026 6:42 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 526
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Scintilla search text without move cursor

Post 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
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 26.1 - Iphone 17 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5614
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Scintilla search text without move cursor

Post 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)
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5614
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Scintilla search text without move cursor

Post 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)
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 526
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Scintilla search text without move cursor [Resolved]

Post by Mindphazer »

Hi KCC
Glad I could help
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 26.1 - Iphone 17 Pro Max - iPad at home
...and unfortunately... Windows at work...
Post Reply