martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.19k stars 260 forks source link

skip empty cells before applying a style #1149

Closed fischerling closed 8 months ago

fischerling commented 8 months ago

Fix empty cells erroneously being styled.

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.

rnpnr commented 8 months ago

Thanks for the patch! Applied in be89a64.