jacobslusser / ScintillaNET

A Windows Forms control, wrapper, and bindings for the Scintilla text editor.
MIT License
963 stars 243 forks source link

Unexpected Character Appears When Using ReplaceSelection #464

Closed AlanBurkhart closed 5 years ago

AlanBurkhart commented 5 years ago

I'm using CTRL + [key] to insert HTML tags with the KeyDown event. This works except that control character #2 appears at the end of the new text. It shows up as "STX". Code:

Dim str As String = sci.SelectedText
If e.Modifiers = Keys.Control Then
    sci.BeginUndoAction()

        Select Case e.KeyCode
            Case Keys.B
                str = "<strong>" & str & "</strong>"
                sci.ReplaceSelection(str)
    End Select
    sci.EndUndoAction()
End If

How to avoid this? Thanks.

AlanBurkhart commented 5 years ago

OK my bad. Should have been using KeyPress instead of KeyDown. Sorry!

xv commented 5 years ago

Also, if you'd like, you can revoke the natively assigned control character input via:

scintilla.AssignCmdKey(Keys.Control | Keys.Whatever, Command.Null);

The following quote is from the author of Scintilla himself:

Control characters are considered normal input unless assigned. Use SCI_ASSIGNCMDKEY to assign these keys to SCI_NULL.

AlanBurkhart commented 5 years ago

Good information, thanks. In truth, I had KeyDown and KeyPress backwards. Once all was in proper order it worked fine.