vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit db0b2f3ddda48f1dca785890d81ecd36c44c81d5 parent 81d473f519f45ec44bd306687189a918473e302b Author: Florian Fischer <florian.fischer@muhq.space> Date: Fri, 13 Oct 2023 15:42:43 +0200 view: skip empty cells before applying a style The view_style function is used to apply styles to ranges of text in a view. It approaches the starting position where the style should be applied by iterating the columns in the appropriate line using this while loop: while (pos < start && col < width) pos += line->cells[col++].len; The while loop will stop at the last character before the range where the style should be applied. This works fine until we encounter "empty" cells between the last cell containing an actual character and the first cell to be styled. This can happen if the last character before the range to style is '\t' which gets expanded with empty cells by vis according to the tabwidth option. Those empty cells get erroneously styled as well. This is fixed by skipping all empty cells encountered before the range to style. fixes #1147: `win:style` styles more terminal cells than expected Diffstat:
| M | view.c | | | 4 | ++++ |
1 file changed, 4 insertions(+), 0 deletions(-)
diff --git a/view.c b/view.c @@ -1428,6 +1428,10 @@ void view_style(View *view, enum UiStyle style_id, size_t start, size_t end) { while (pos < start && col < width) pos += line->cells[col++].len; + /* skip empty columns */ + while (!line->cells[col].len && col < width) + col++; + do { while (pos <= end && col < width) { pos += line->cells[col].len;