about summary refs log tree commit diff stats
path: root/src/render
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-12-12 01:03:06 +0100
committerbptato <nincsnevem662@gmail.com>2022-12-12 01:03:06 +0100
commit23da83a2faac129271cfd7b9761588301280a9fe (patch)
tree165f415f25db1cd548eb1cb6b167cffaf8bf1e77 /src/render
parent4874b92f0d177c0a7e84c1dd106f9b16eec7cb05 (diff)
downloadchawan-23da83a2faac129271cfd7b9761588301280a9fe.tar.gz
renderdocument: fix overwriting formatcells
Gets rid of weird underline effects. Also fixes nx calculation, I think.
Diffstat (limited to 'src/render')
-rw-r--r--src/render/renderdocument.nim13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/render/renderdocument.nim b/src/render/renderdocument.nim
index 2a938acc..5493c2f5 100644
--- a/src/render/renderdocument.nim
+++ b/src/render/renderdocument.nim
@@ -50,14 +50,12 @@ proc setText(lines: var FlexibleGrid, linestr: string, cformat: ComputedFormat,
 
   let ostr = lines[y].str.substr(i)
   lines[y].str.setLen(i)
-  var linestrwidth = 0
   let padwidth = x - cx
   if padwidth > 0:
     lines[y].str &= ' '.repeat(padwidth)
-    linestrwidth += padwidth
 
   lines[y].str &= linestr
-  linestrwidth += linestr.width()
+  let linestrwidth = linestr.width()
 
   i = 0
   var nx = x # last x of new string
@@ -103,12 +101,15 @@ proc setText(lines: var FlexibleGrid, linestr: string, cformat: ComputedFormat,
 
   # Now for the text's formats:
   var format = cformat.formatFromWord()
+  var lformat: Format
   if fi == -1:
     # No formats => just insert a new format at 0
     inc fi
     lines[y].insertFormat(x, fi, format, cformat)
+    lformat = newFormat()
   else:
     # First format's pos may be == x here.
+    lformat = lines[y].formats[fi].format # save for later use
     if lines[y].formats[fi].pos == x:
       # Replace.
       format.bgcolor = lines[y].formats[fi].format.bgcolor
@@ -126,10 +127,16 @@ proc setText(lines: var FlexibleGrid, linestr: string, cformat: ComputedFormat,
     # Other formats must be > x => replace them
     format.bgcolor = lines[y].formats[fi].format.bgcolor
     let px = lines[y].formats[fi].pos
+    lformat = lines[y].formats[fi].format # save for later use
     lines[y].formats.delete(fi)
     lines[y].insertFormat(px, fi, format, cformat)
     inc fi
 
+  if i < ostr.len:
+    # nx < ostr.width, so insert the continuation of the last format we
+    # replaced after our string. (default format when the last didn't exist.)
+    lines[y].insertFormat(nx, fi, lformat)
+
   dec fi # go back to previous format, so that pos <= nx
   assert lines[y].formats[fi].pos <= nx
   # That's it!