widget: maintain Editor caret position

Only call layoutCaret when the text layout changes, adjust position
for caret movement.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-06-19 23:32:53 +02:00
parent 8f31f8da2c
commit ef21a7ace1
2 changed files with 123 additions and 78 deletions
-12
View File
@@ -152,18 +152,6 @@ func (e *editBuffer) dump() {
}
}
func (e *editBuffer) move(runes int) {
for ; runes < 0 && e.caret > 0; runes++ {
_, s := e.runeBefore(e.caret)
e.caret -= s
}
for ; runes > 0 && e.caret < e.len(); runes-- {
_, s := e.runeAt(e.caret)
e.caret += s
}
e.dump()
}
func (e *editBuffer) runeBefore(idx int) (rune, int) {
if idx > e.gapstart {
idx += e.gapLen()