From b0cb1bedd8ffcc78d4a344ae8815d9cf7d8283a6 Mon Sep 17 00:00:00 2001 From: "Luke I. Wilson" Date: Thu, 11 Mar 2021 23:16:19 -0600 Subject: [PATCH] Fix cursor column tracking in TextEdit --- ui/textedit.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ui/textedit.go b/ui/textedit.go index 1f80b91..2ce2a9a 100644 --- a/ui/textedit.go +++ b/ui/textedit.go @@ -181,6 +181,7 @@ func (t *TextEdit) Insert(contents string) { t.SetLineCol(t.cury, t.curx+1) // Advance the cursor } } + t.prevCurCol = t.curx } // insertNewLine inserts a line break at the cursor and sets the cursor position to the first @@ -198,6 +199,7 @@ func (t *TextEdit) insertNewLine() { t.buffer[t.cury+1] = string(newLineRunes) // Assign the new line t.SetLineCol(t.cury+1, 0) // Go to start of new line + t.prevCurCol = t.curx } // GetLineCol returns (line, col) of the cursor. Zero is origin for both. @@ -402,12 +404,16 @@ func (t *TextEdit) HandleEvent(event tcell.Event) bool { t.CursorRight() case tcell.KeyHome: t.SetLineCol(t.cury, 0) + t.prevCurCol = t.curx case tcell.KeyEnd: t.SetLineCol(t.cury, len(t.buffer[t.cury])) + t.prevCurCol = t.curx case tcell.KeyPgUp: t.SetLineCol(t.scrolly-t.height, t.curx) // Go a page up + t.prevCurCol = t.curx case tcell.KeyPgDn: t.SetLineCol(t.scrolly+t.height*2-1, t.curx) // Go a page down + t.prevCurCol = t.curx // Deleting case tcell.KeyBackspace: