summaryrefslogtreecommitdiff
path: root/src/highlighters.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2025-06-28 12:29:28 +1000
committerMaxime Coste <mawww@kakoune.org>2025-06-28 12:41:46 +1000
commit767a7df6c9b614f1a1c623027758ee3dbd25a75e (patch)
treefb89edb8d9f45c1d86c68476469c45f710d68c90 /src/highlighters.cc
parentee23c00b569f31430ca5b6a1f01596f7df55f900 (diff)
Fix wrap interaction with show-whitespaces and test word wrapping more
Consider atom boundaries as word boundaries, which should be correct du to passes ordering. Fixes #5350
Diffstat (limited to 'src/highlighters.cc')
-rw-r--r--src/highlighters.cc22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/highlighters.cc b/src/highlighters.cc
index 5dc2b38a..ff46081a 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -676,8 +676,8 @@ struct WrapHighlighter : Highlighter
bool next_split_pos(SplitPos& pos, DisplayLine::iterator line_end,
ColumnCount wrap_column, ColumnCount prefix_len) const
{
- SplitPos last_word_boundary = pos;
- SplitPos last_WORD_boundary = pos;
+ SplitPos last_word_boundary{};
+ SplitPos last_WORD_boundary{};
auto update_word_boundaries = [&](Codepoint cp) {
if (m_word_wrap and not is_word<Word>(cp))
@@ -704,6 +704,9 @@ struct WrapHighlighter : Highlighter
{
++pos.atom_it;
pos.byte = 0;
+ // Thanks to the pass ordering, atom boundary should always be reasonable word split points
+ last_word_boundary = pos;
+ last_WORD_boundary = pos;
}
}
if (pos.atom_it == line_end)
@@ -713,7 +716,7 @@ struct WrapHighlighter : Highlighter
if (m_word_wrap and pos.byte < content.length())
{
auto find_split_pos = [&](SplitPos start_pos, auto is_word) {
- if (start_pos.byte == 0)
+ if (start_pos.column == 0)
return false;
const char* it = &content[pos.byte];
// split at current position if is a word boundary
@@ -721,16 +724,19 @@ struct WrapHighlighter : Highlighter
return true;
// split at last word boundary if the word is shorter than our wrapping width
ColumnCount word_length = pos.column - start_pos.column;
- while (it != content.end() and word_length <= (wrap_column - prefix_len))
+ ColumnCount max_word_length = wrap_column - prefix_len;
+ while (it != content.end() and word_length <= max_word_length)
{
const Codepoint cp = utf8::read_codepoint(it, content.end());
if (not is_word(cp, {'_'}))
- {
- pos = start_pos;
- return true;
- }
+ break;
word_length += codepoint_width(cp);
}
+ if (word_length <= max_word_length)
+ {
+ pos = start_pos;
+ return true;
+ }
return false;
};
if (find_split_pos(last_WORD_boundary, is_word<WORD>) or