aboutsummaryrefslogtreecommitdiff
path: root/view.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-05-05 11:08:15 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-05-05 11:15:10 +0200
commit54b734939eea44ae84578daaa8e67f8110da7e4f (patch)
tree045a94a601cacda40b8756c91220b1219ab3f271 /view.c
parentb2800904b8cb8269c0e750dced51e8dc422af8f5 (diff)
downloadvis-54b734939eea44ae84578daaa8e67f8110da7e4f.tar.gz
vis-54b734939eea44ae84578daaa8e67f8110da7e4f.tar.xz
view: try to recover from invalid cursor positions
A cursor is a mark, if the text containing the mark is removed the cursor is lost. In this case we try to fall back to the previously known cursor position/mark. This should improve undo operations for filter commands.
Diffstat (limited to 'view.c')
-rw-r--r--view.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/view.c b/view.c
index 91df559..26821c3 100644
--- a/view.c
+++ b/view.c
@@ -54,6 +54,7 @@ struct Cursor { /* cursor position */
int lastcol; /* remembered column used when moving across lines */
Line *line; /* screen line on which cursor currently resides */
Mark mark; /* mark used to keep track of current cursor position */
+ Mark mark_old; /* previous value of the mark, used to recover cursor position */
Selection *sel; /* selection (if any) which folows the cursor upon movement */
Mark lastsel_anchor;/* previously used selection data, */
Mark lastsel_cursor;/* used to restore it */
@@ -434,6 +435,7 @@ static bool view_addch(View *view, Cell *cell) {
static void cursor_to(Cursor *c, size_t pos) {
Text *txt = c->view->text;
+ c->mark_old = c->mark;
c->mark = text_mark_set(txt, pos);
if (pos != c->pos)
c->lastcol = 0;
@@ -1256,7 +1258,8 @@ Cursor *view_cursors_next(Cursor *c) {
}
size_t view_cursors_pos(Cursor *c) {
- return text_mark_get(c->view->text, c->mark);
+ size_t pos = text_mark_get(c->view->text, c->mark);
+ return pos != EPOS ? pos : text_mark_get(c->view->text, c->mark_old);
}
size_t view_cursors_line(Cursor *c) {