Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions PureBasicIDE/ScintillaHighlighting.pb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
; See LICENSE and LICENSE-FANTAISIE in the project root for license information.
; --------------------------------------------------------------------------------------------



CompilerIf #CompileWindows | #CompileLinux | #CompileMac

#SCI_NORM = 0
Expand Down Expand Up @@ -3501,17 +3499,31 @@ CompilerIf #CompileWindows | #CompileLinux | #CompileMac
SetBackgroundColor(Gadget) ; updates the 'disabled background color'
EndProcedure


Procedure InsertCodeString(String$)

If *ActiveSource\Parser\Encoding = 1 ; utf8
Format = #PB_UTF8
Else
Format = #PB_Ascii
EndIf

; Embed insertion into a single transaction, otherwise the insertion mark will reappear in an Undo action.
SendEditorMessage(#SCI_BEGINUNDOACTION, 0, 0)

CurrentPos = SendEditorMessage(#SCI_GETCURRENTPOS, 0, 0)
Converted$ = Space(StringByteLength(String$, Format))
PokeS(@Converted$, String$, -1, Format)
SendEditorMessage(#SCI_REPLACESEL, 0, @Converted$)

; Remove marker and move caret, if a position is specified.
MarkerOffset = FindString(String$, "^")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to take care of possible UTF-8 encoding here (see the Format variable). The scintilla commands usually take byte offsets, not character positions. Best is to do some testing with accented or other special characters and try both UTF8 and Ascii to make sure both work right.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I just noticed that the procedure you modified (InsertCodeString()) is used in multiple places in the IDE. So placing this caret move code in there could have some side effect on another use case, maybe.

Why not add a new parameter to the procedure to enable/disable this behavior? This way it will not affect anything outside of the template functionality. You can make it an optional parameter so existing code does not need to be changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done.

If MarkerOffset > 0
SendEditorMessage(#SCI_GOTOPOS, CurrentPos + MarkerOffset - 1)
SendEditorMessage(#SCI_DELETERANGE, CurrentPos + MarkerOffset - 1, 1)
EndIf

SendEditorMessage(#SCI_ENDUNDOACTION, 0, 0)

EndProcedure

Procedure Undo()
Expand Down