diff options
Diffstat (limited to 'src/lexer.c')
| -rw-r--r-- | src/lexer.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/lexer.c b/src/lexer.c index 2f43b76..840596a 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -212,22 +212,35 @@ teco_lexer_style(teco_view_t *view, gsize end) gsize start = teco_view_ssm(view, SCI_GETENDSTYLED, 0, 0); guint start_line = teco_view_ssm(view, SCI_LINEFROMPOSITION, start, 0); - gint start_col = 0; /* * The line state stores the laster character (column) in bytes, * that starts from a fresh parser state. * It's -1 if the line does not have a clean parser state. - * Therefore we search for the first line before `start` that has a - * known clean parser state. + * If the cached position on start_line does not fit our needs, + * we backtrack and search in previous lines + * for a known clean parser state. + * + * NOTE: It's crucial to consider the line state of the first possible + * line since we might be styling for a single-line command line view. + * + * FIXME: During rubout of regular commands we will frequently have the + * situation that the cached line state points after the last styled position + * forcing us to restyle the entire command line macro. + * If this turns out to be problematic, we might detect that + * view == teco_cmdline.view and inspect teco_cmdline.machine. */ - if (start_line > 0) { + gint start_col = teco_view_ssm(view, SCI_GETLINESTATE, start_line, 0); + if (start_col > start - teco_view_ssm(view, SCI_POSITIONFROMLINE, start_line, 0)) + /* we are asked to style __before__ the last known start state */ + start_col = -1; + if (start_col < 0 && start_line > 0) { do start_line--; while ((start_col = teco_view_ssm(view, SCI_GETLINESTATE, start_line, 0)) < 0 && start_line > 0); - start_col = MAX(start_col, 0); } + start_col = MAX(start_col, 0); start = teco_view_ssm(view, SCI_POSITIONFROMLINE, start_line, 0) + start_col; g_assert(end > start); |
