vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit e18612bb86a092d785e661f885065942441435d6 parent 4ccaa83f43c6feff2777dbd9787ec1f467e8a842 Author: Marc André Tanner <mat@brain-dump.org> Date: Sun, 26 Jul 2015 17:13:55 +0200 view: use a mark to keep track of the visible area This should fix "corruptions" caused by wrong offsets when editing the same file in multiple windows. Diffstat:
| M | view.c | | | 12 | ++++++++++-- |
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/view.c b/view.c @@ -53,6 +53,8 @@ struct View { ViewEvent *events; int width, height; /* size of display area */ Filepos start, end; /* currently displayed area [start, end] in bytes from the start of the file */ + Filepos start_last; /* previously used start of visible area, used to update the mark */ + Mark start_mark; /* mark to keep track of the start of the visible area */ size_t lines_size; /* number of allocated bytes for lines (grows only) */ Line *lines; /* view->height number of lines representing view content */ Line *topline; /* top of the view, first line currently shown */ @@ -100,8 +102,14 @@ void view_tabwidth_set(View *view, int tabwidth) { /* reset internal view data structures (cell matrix, line offsets etc.) */ static void view_clear(View *view) { - /* calculate line number of first line */ - // TODO move elsewhere + if (view->start != view->start_last) { + view->start_mark = text_mark_set(view->text, view->start); + view->start_last = view->start; + } else { + size_t start = text_mark_get(view->text, view->start_mark); + if (start != EPOS) + view->start = start; + } view->topline = view->lines; view->topline->lineno = text_lineno_by_pos(view->text, view->start); view->lastline = view->topline;