about summary refs log tree commit diff stats
path: root/src/layout
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-06-02 18:54:06 +0200
committerbptato <nincsnevem662@gmail.com>2024-06-02 18:54:06 +0200
commit32b2736d92b3f94343c91e86ad9dc67ec2e453b7 (patch)
tree316eb8c5b34c33ea34f3c94f303b8ff3399cb908 /src/layout
parentd15b6bb7c6f47c81e37f6e86a078ff754d3bfabf (diff)
downloadchawan-32b2736d92b3f94343c91e86ad9dc67ec2e453b7.tar.gz
renderdocument: handle overlapping double width chars
See attached test case; previously, this would result in a missing space
in visual mode and a crash in dump mode.
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/renderdocument.nim7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/layout/renderdocument.nim b/src/layout/renderdocument.nim
index e62455e4..c6277646 100644
--- a/src/layout/renderdocument.nim
+++ b/src/layout/renderdocument.nim
@@ -101,7 +101,7 @@ proc setText(grid: var FlexibleGrid; linestr: string; x, y: int; format: Format;
     grid[y].str &= ' '.repeat(padwidth)
 
   grid[y].str &= linestr
-  let linestrwidth = linestr.twidth(x)
+  var linestrwidth = linestr.twidth(x)
 
   i = 0
   var nx = x # last x of new string
@@ -109,6 +109,11 @@ proc setText(grid: var FlexibleGrid; linestr: string; x, y: int; format: Format;
     fastRuneAt(ostr, i, r)
     nx += r.twidth(nx)
 
+  while x + linestrwidth < nx:
+    # we ate half of a double width char; pad it out with spaces.
+    grid[y].str &= ' '
+    inc linestrwidth
+
   if i < ostr.len:
     grid[y].str &= ostr.substr(i)