vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 777c1e7819438585a9ae75e2dd552ed912b8a237
parent 1b7e6348ae9b51bae5ae4faf1a0a5f1752652a03
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Wed, 22 Mar 2017 08:22:23 +0100

vis: fix syntax highlighting glitches with split windows

When a file was being displayed in multiple windows and changes were
performed to the one showing the preceding file region, the syntax
highlighting of the window showing the later parts would get messed up.

Diffstat:
Mvis.c | 31++++++++++++++-----------------
Mvis.h | 1+
2 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/vis.c b/vis.c @@ -264,17 +264,6 @@ void vis_window_status(Win *win, const char *status) { win->ui->status(win->ui, status); } -static void windows_invalidate(Vis *vis, size_t start, size_t end) { - for (Win *win = vis->windows; win; win = win->next) { - if (vis->win->file == win->file) { - Filerange view = view_viewport_get(win->view); - if ((view.start <= start && start <= view.end) || - (view.start <= end && end <= view.end)) - view_draw(win->view); - } - } -} - void window_selection_save(Win *win) { File *file = win->file; Filerange sel = view_cursors_selection_get(view_cursors(win->view)); @@ -473,6 +462,14 @@ void vis_window_draw(Win *win) { vis_event_emit(vis, VIS_EVENT_WIN_STATUS, win); } + +void vis_window_invalidate(Win *win) { + for (Win *w = win->vis->windows; w; w = w->next) { + if (w->file == win->file) + view_draw(w->view); + } +} + Win *window_new_file(Vis *vis, File *file, enum UiOption options) { Win *win = calloc(1, sizeof(Win)); if (!win) @@ -761,7 +758,7 @@ void vis_free(Vis *vis) { void vis_insert(Vis *vis, size_t pos, const char *data, size_t len) { text_insert(vis->win->file->text, pos, data, len); - windows_invalidate(vis, pos, pos + len); + vis_window_invalidate(vis->win); } void vis_insert_key(Vis *vis, const char *data, size_t len) { @@ -793,7 +790,7 @@ void vis_replace_key(Vis *vis, const char *data, size_t len) { void vis_delete(Vis *vis, size_t pos, size_t len) { text_delete(vis->win->file->text, pos, len); - windows_invalidate(vis, pos, pos + len); + vis_window_invalidate(vis->win); } bool vis_action_register(Vis *vis, const KeyAction *action) { @@ -1638,8 +1635,9 @@ size_t vis_text_insert_nl(Vis *vis, Text *txt, size_t pos) { } void vis_insert_nl(Vis *vis) { - View *view = vis->win->view; - Text *txt = vis->win->file->text; + Win *win = vis->win; + View *view = win->view; + Text *txt = win->file->text; for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c)) { size_t pos = view_cursors_pos(c); size_t newpos = vis_text_insert_nl(vis, txt, pos); @@ -1651,8 +1649,7 @@ void vis_insert_nl(Vis *vis) { view_cursors_to(c, pos); view_cursors_to(c, newpos); } - size_t pos = view_cursor_get(view); - windows_invalidate(vis, pos, pos-1); + vis_window_invalidate(win); } Regex *vis_regex(Vis *vis, const char *pattern) { diff --git a/vis.h b/vis.h @@ -119,6 +119,7 @@ bool vis_window_split(Win*); /* change status message of this window */ void vis_window_status(Win*, const char *status); void vis_window_draw(Win*); +void vis_window_invalidate(Win*); /* focus the next / previous window */ void vis_window_next(Vis*); void vis_window_prev(Vis*);