delete unicode chars with length > 1 correctly

When there were non ASCII characters (for exemple éèàçîï) in a deleted
selection or word, more characters were deleted because there was a
mismatch between runes and bytes in Delete and deleteWord

Fixes: https://todo.sr.ht/~eliasnaur/gio/330
Signed-off-by: Fabien Jansem <fabien@jansem.eu.org>
This commit is contained in:
Fabien Jansem
2022-01-02 13:13:23 +01:00
committed by Elias Naur
parent ac3bbc72ac
commit 9b7ec167bc
3 changed files with 145 additions and 10 deletions
+19
View File
@@ -46,6 +46,25 @@ func (e *editBuffer) deleteRunes(caret, runes int) int {
return caret
}
func (e *editBuffer) deleteBytes(caret, bytes int) int {
e.moveGap(caret, 0)
if bytes < 0 {
e.gapstart += bytes
if e.gapstart < 0 {
e.gapstart = 0
}
caret = e.gapstart
}
if bytes > 0 {
e.gapend += bytes
if e.gapend > len(e.text) {
e.gapend = len(e.text)
}
}
e.changed = e.changed || bytes != 0
return caret
}
// moveGap moves the gap to the caret position. After returning,
// the gap is guaranteed to be at least space bytes long.
func (e *editBuffer) moveGap(caret, space int) {