Scintilla save point
Scintilla save point
Please advise, I can't find information on Scintilla. Do I need it to save the position in the open tab, i.e. if I scroll down the text, when I press the button it returns to the saved state? i.e. save the current state and load. What functions should be used for this?
Re: Scintilla save point
The Scintilla home page is at https://www.scintilla.org/index.html, the documentation at https://www.scintilla.org/ScintillaDoc.html.
Save point has a specific meaning in Scintilla, it is part of the undo/redo stack process though, it has nothing to do with the caret position. Caret positions and scrolls are not recorded in the undo stack by the gadget, so don't be fooled into thinking that's what you are looking for in the documentation.
In order to get the behaviour you describe I think you would need to do something like:
1. Keep track of the current caret position via #SCI_GETCURRENTPOS when a #SCN_CHARADDED notification occurs.
2. Copy the tracked caret position to a 'bookmark' position when the #SCN_UPDATEUI notification occurs with an 'updated' value having the #SC_UPDATE_V_SCROLL or #SC_UPDATE_H_SCROLL bit set.
3. Restore the bookmark position via #SCI_SETCURRENTPOS when your button is clicked.
Save point has a specific meaning in Scintilla, it is part of the undo/redo stack process though, it has nothing to do with the caret position. Caret positions and scrolls are not recorded in the undo stack by the gadget, so don't be fooled into thinking that's what you are looking for in the documentation.
In order to get the behaviour you describe I think you would need to do something like:
1. Keep track of the current caret position via #SCI_GETCURRENTPOS when a #SCN_CHARADDED notification occurs.
2. Copy the tracked caret position to a 'bookmark' position when the #SCN_UPDATEUI notification occurs with an 'updated' value having the #SC_UPDATE_V_SCROLL or #SC_UPDATE_H_SCROLL bit set.
3. Restore the bookmark position via #SCI_SETCURRENTPOS when your button is clicked.
Re: Scintilla save point
No, you didn't get it, I need the current cursor position to be saved and returned to that place when the button is pressed.
Something like this:
Maybe there are already ready-made procedures for this?
Something like this:
Code: Select all
procedure save_point()
position_line = ScintillaSendMessage(#SC, #SCI_GETCURLINE)
position_cursor=ScintillaSendMessage(#SC,#SCI_GETCURRENTPOS)
endprocedure
procedure load_point()
For i=1 To position_line
ScintillaSendMessage(#SC, #SCI_LINESCROLLDOWN)
Next i
ScintillaSendMessage(#SC,#SCI_SETCURRENTPOS, position_cursor)
endprocedureRe: Scintilla save point
Taken from FindAllReferences
Adapted for gadget
Adapted for gadget
Code: Select all
Procedure JumpToLine(SelectedLine)
Protected Count
CursorLine = ScintillaSendMessage(#SC, #SCI_GETCURRENTPOS, 0, 0)
CursorLine = ScintillaSendMessage(#SC, #SCI_LINEFROMPOSITION, CursorLine, 0)
; Debug SelectedLine
ScintillaSendMessage(#SC, #SCI_ENSUREVISIBLE, SelectedLine - 1, 0) ; Guarantees the visibility of the line, expands if necessary.
ScintillaSendMessage(#SC, #SCI_GOTOLINE, SelectedLine - 1, 0)
Count = ScintillaSendMessage(#SC, #SCI_LINESONSCREEN, 0, 0) / 2
; ScintillaSendMessage(#SC, #SCI_SETFIRSTVISIBLELINE, SelectedLine - Count - 1, 0)
ScintillaSendMessage(#SC, #SCI_SCROLLCARET, SelectedLine - 1, 0) ; scrolls to cursor
; Aligns well, except if the line is inside a fold
; Need a condition if the row is not available
; If CursorLine > SelectedLine
; Count = -Count
; EndIf
If Abs(CursorLine - SelectedLine) < Count
Count = 0
ElseIf CursorLine > SelectedLine
Count = - Count
EndIf
ScintillaSendMessage(#SC, #SCI_LINESCROLL, 0, Count) ; scrolls another half screen of visible lines
; ScintillaSendMessage(#SC, #SCI_SCROLLRANGE, SelectedLine - 1, SelectedLine - 1)
; Debug Count
; MessageRequester("", Str(Count))
; ScintillaSendMessage(#SC, #SCI_ENSUREVISIBLE, SelectedLine - 1, 0)
EndProcedureRe: Scintilla save point
Thank you! It works!

