mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 00:16:15 +00:00
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:
committed by
Elias Naur
parent
ac3bbc72ac
commit
9b7ec167bc
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user