aboutsummaryrefslogtreecommitdiff
path: root/view.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-07-26 17:13:55 +0200
committerMarc André Tanner <mat@brain-dump.org>2015-07-26 17:13:55 +0200
commit0b123867775b74fb7d247ea970f01d26423264b7 (patch)
treec6f5fb58e72dcbd13729f905785cad9cc0dfa259 /view.c
parenta4ae277139a221faffa20b130a002e1f2e7e460a (diff)
downloadvis-0b123867775b74fb7d247ea970f01d26423264b7.tar.gz
vis-0b123867775b74fb7d247ea970f01d26423264b7.tar.xz
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 (limited to 'view.c')
-rw-r--r--view.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/view.c b/view.c
index 3bbb1cb..f30af09 100644
--- 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;