aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-01-11 16:27:39 +0100
committerbptato <nincsnevem662@gmail.com>2023-01-11 16:27:39 +0100
commit4ec160f63168fc385e9021ba376162de4f050234 (patch)
treea9e9ac906a44f956d422ae97c218fd8279fc0ba2 /src/buffer
parent913fabdcea70bdf4eb85306dd1a10361786b0077 (diff)
downloadchawan-4ec160f63168fc385e9021ba376162de4f050234.tar.gz
buffer/container: fix cursor overwriting double-width chars
In some terminals, placing the cursor on the second cell of a double-width character deletes half of said character, so let's not do that.
Diffstat (limited to 'src/buffer')
-rw-r--r--src/buffer/container.nim23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/buffer/container.nim b/src/buffer/container.nim
index 3315b79c..38b58011 100644
--- a/src/buffer/container.nim
+++ b/src/buffer/container.nim
@@ -183,8 +183,29 @@ func cursorLastX(container: Container): int =
w += r.twidth(w)
return max(w - 1, 0)
+# Last cell for tab, first cell for everything else (e.g. double width.)
+# This is needed because moving the cursor to the 2nd cell of a double
+# width character clears it on some terminals.
+func cursorDispX(container: Container): int =
+ if container.numLines == 0: return 0
+ let line = container.currentLine
+ if line.len == 0: return 0
+ var w = 0
+ var pw = 0
+ var i = 0
+ var r: Rune
+ let cc = container.cursorx
+ while i < line.len and w <= cc:
+ fastRuneAt(line, i, r)
+ pw = w
+ w += r.twidth(w)
+ if r == Rune('\t'):
+ return max(w - 1, 0)
+ else:
+ return pw
+
func acursorx*(container: Container): int =
- max(0, container.cursorLastX() - container.fromx)
+ max(0, container.cursorDispX() - container.fromx)
func acursory*(container: Container): int =
container.cursory - container.fromy