summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2023-02-15 13:04:53 +1100
committerMaxime Coste <mawww@kakoune.org>2023-02-15 13:04:53 +1100
commitafaa47e93fb937fbedb60bcdbc768bb937108f86 (patch)
treeca6a0c67e8df72276be9c8168204d20eef59a67c
parent0630b4f4f6f006702bbff973309f2487b9fab001 (diff)
Fix trimming of line front halfway through a double-width glyph
Insert a space to replace the half glyph and ensure the rest of the line is correctly aligned. Fixes #4843
-rw-r--r--src/display_buffer.cc8
-rw-r--r--test/regression/4843-trim-front-split-glyph/cmd1
-rw-r--r--test/regression/4843-trim-front-split-glyph/in4
-rw-r--r--test/regression/4843-trim-front-split-glyph/rc2
-rw-r--r--test/regression/4843-trim-front-split-glyph/script2
5 files changed, 15 insertions, 2 deletions
diff --git a/src/display_buffer.cc b/src/display_buffer.cc
index 0fd180b6..d88d02fe 100644
--- a/src/display_buffer.cc
+++ b/src/display_buffer.cc
@@ -253,14 +253,18 @@ bool DisplayLine::trim_from(ColumnCount first_col, ColumnCount front, ColumnCoun
}
auto front_it = it;
+ Face last_face{};
while (front > 0 and it != end())
{
front -= it->trim_begin(front);
- kak_assert(it->empty() or front == 0);
+ kak_assert(it->empty() or front <= 0);
+ last_face = it->face;
if (it->empty())
++it;
}
- m_atoms.erase(front_it, it);
+ it = m_atoms.erase(front_it, it);
+ if (front < 0)
+ it = m_atoms.insert(it, DisplayAtom{String{' ', -front}, last_face});
it = begin();
for (; it != end() and col_count > 0; ++it)
diff --git a/test/regression/4843-trim-front-split-glyph/cmd b/test/regression/4843-trim-front-split-glyph/cmd
new file mode 100644
index 00000000..907720af
--- /dev/null
+++ b/test/regression/4843-trim-front-split-glyph/cmd
@@ -0,0 +1 @@
+lvl
diff --git a/test/regression/4843-trim-front-split-glyph/in b/test/regression/4843-trim-front-split-glyph/in
new file mode 100644
index 00000000..51d35dda
--- /dev/null
+++ b/test/regression/4843-trim-front-split-glyph/in
@@ -0,0 +1,4 @@
+abc
+⌛c
+⌛d
+⌛e
diff --git a/test/regression/4843-trim-front-split-glyph/rc b/test/regression/4843-trim-front-split-glyph/rc
new file mode 100644
index 00000000..a192f572
--- /dev/null
+++ b/test/regression/4843-trim-front-split-glyph/rc
@@ -0,0 +1,2 @@
+add-highlighter window/ regex d 0:green
+add-highlighter window/ regex ^[^\n]+e 0:yellow
diff --git a/test/regression/4843-trim-front-split-glyph/script b/test/regression/4843-trim-front-split-glyph/script
new file mode 100644
index 00000000..fbb4bb88
--- /dev/null
+++ b/test/regression/4843-trim-front-split-glyph/script
@@ -0,0 +1,2 @@
+ui_out -ignore 1
+ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "black", "bg": "white", "underline": "default", "attributes": [] }, "contents": "b" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "c\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "c\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "green", "bg": "default", "underline": "default", "attributes": [] }, "contents": "d" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "\u000a" }], [{ "face": { "fg": "yellow", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "yellow", "bg": "default", "underline": "default", "attributes": [] }, "contents": "e" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "\u000a" }]], { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }] }'