Please consider the code:
Dim cursorpos As Integer
If Key.Code = Key.Left Or Key.Code = Key.Up Or Key.code = Key.Right Or Key.Code = Key.Down Or Key.Code = Key.Delete Or Key.Code = Key.Backspace Then
cursorpos = TextEdit1.Pos ' just pick the position
Print cursorpos
Else
cursorpos = TextEdit1.Pos
Print cursorpos
TextEdit1.RichText = "<font color = \"#224444\">" & Replace(TextEdit1.Text, gb.NewLine, "<br>") & "</font>" ' this updates the HTML color of the newly added character, preserves the newlines, and replaces them with a <br> for the rich text
Print "setting : ", cursorpos ' prints the correct value
TextEdit1.Pos = cursorpos ' does not work
Print "got : ", TextEdit1.Pos ' jumps to the end of the string
Endif
Now, I write :I have a typo on the first line. I use my arrow key to get there. I hit backspace twice, and remove the wordThis si a line
this is a second line
. All good. Now I expect to type in the character i, and the cursor should stay just after the character i. But as soon as the i is typed in the correct position, the cursor jumps to the end of the text.si
Please help. How can I keep the cursor position in the correct place? Thank you.