diff options
| -rw-r--r-- | src/highlighters.cc | 22 | ||||
| -rw-r--r-- | test/highlight/wrap/interact-with-show-whitespaces/cmd | 1 | ||||
| -rw-r--r-- | test/highlight/wrap/interact-with-show-whitespaces/in | 1 | ||||
| -rw-r--r-- | test/highlight/wrap/interact-with-show-whitespaces/rc | 2 | ||||
| -rw-r--r-- | test/highlight/wrap/interact-with-show-whitespaces/script | 4 | ||||
| -rw-r--r-- | test/highlight/wrap/word/cmd | 1 | ||||
| -rw-r--r-- | test/highlight/wrap/word/in | 3 | ||||
| -rw-r--r-- | test/highlight/wrap/word/rc | 1 | ||||
| -rw-r--r-- | test/highlight/wrap/word/script | 4 |
9 files changed, 31 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 diff --git a/test/highlight/wrap/interact-with-show-whitespaces/cmd b/test/highlight/wrap/interact-with-show-whitespaces/cmd new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/highlight/wrap/interact-with-show-whitespaces/cmd @@ -0,0 +1 @@ + diff --git a/test/highlight/wrap/interact-with-show-whitespaces/in b/test/highlight/wrap/interact-with-show-whitespaces/in new file mode 100644 index 00000000..d675fa44 --- /dev/null +++ b/test/highlight/wrap/interact-with-show-whitespaces/in @@ -0,0 +1 @@ +foo bar diff --git a/test/highlight/wrap/interact-with-show-whitespaces/rc b/test/highlight/wrap/interact-with-show-whitespaces/rc new file mode 100644 index 00000000..37119e08 --- /dev/null +++ b/test/highlight/wrap/interact-with-show-whitespaces/rc @@ -0,0 +1,2 @@ +add-highlighter window/ wrap -word -width 5 +add-highlighter window/ show-whitespaces diff --git a/test/highlight/wrap/interact-with-show-whitespaces/script b/test/highlight/wrap/interact-with-show-whitespaces/script new file mode 100644 index 00000000..538ab98a --- /dev/null +++ b/test/highlight/wrap/interact-with-show-whitespaces/script @@ -0,0 +1,4 @@ +ui_out '{ "jsonrpc": "2.0", "method": "set_ui_options", "params": [{}] }' +ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "black", "bg": "white", "underline": "default", "attributes": [] }, "contents": "f" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "oo" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": ["final_fg"] }, "contents": "·" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "bar" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": ["final_fg"] }, "contents": "¬" }]], { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }] }' +ui_out -until '{ "jsonrpc": "2.0", "method": "refresh", "params": [true] }' + diff --git a/test/highlight/wrap/word/cmd b/test/highlight/wrap/word/cmd new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/highlight/wrap/word/cmd @@ -0,0 +1 @@ + diff --git a/test/highlight/wrap/word/in b/test/highlight/wrap/word/in new file mode 100644 index 00000000..5cdc9a1d --- /dev/null +++ b/test/highlight/wrap/word/in @@ -0,0 +1,3 @@ +123456789 wrap +123456 wrap +123456 wrap 1234 wrap 123456789012 wrap diff --git a/test/highlight/wrap/word/rc b/test/highlight/wrap/word/rc new file mode 100644 index 00000000..921daf40 --- /dev/null +++ b/test/highlight/wrap/word/rc @@ -0,0 +1 @@ +add-highlighter window/ wrap -word -width 10 diff --git a/test/highlight/wrap/word/script b/test/highlight/wrap/word/script new file mode 100644 index 00000000..eb18dadc --- /dev/null +++ b/test/highlight/wrap/word/script @@ -0,0 +1,4 @@ +ui_out '{ "jsonrpc": "2.0", "method": "set_ui_options", "params": [{}] }' +ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "black", "bg": "white", "underline": "default", "attributes": [] }, "contents": "1" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "23456789 " }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "wrap\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "123456 " }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "wrap\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "123456 " }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "wrap 1234 " }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "wrap 12345" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "6789012 " }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "wrap\u000a" }]], { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }] }' +ui_out -until '{ "jsonrpc": "2.0", "method": "refresh", "params": [true] }' + |
