aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-01-14 11:02:52 +0100
committerMarc André Tanner <mat@brain-dump.org>2017-01-14 11:02:52 +0100
commitf9a147a50f33f0e27858bddead52d60ce8b46591 (patch)
tree621ac4d7ee982d76e05a7808690890fc93f5e6b9
parent7f0309f5835f12396a395681d8abfc3d844d3ae8 (diff)
downloadvis-f9a147a50f33f0e27858bddead52d60ce8b46591.tar.gz
vis-f9a147a50f33f0e27858bddead52d60ce8b46591.tar.xz
view: enforce invariant that cursor is within selection
A cursor does not necessarily have to be at a selection boundary (e.g. in visual line mode) but it has to be within the selection.
-rw-r--r--view.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/view.c b/view.c
index 5352a0f..8b7238e 100644
--- a/view.c
+++ b/view.c
@@ -1276,8 +1276,8 @@ void view_cursors_selection_sync(Cursor *c) {
if (!c->sel)
return;
Text *txt = c->view->text;
- size_t cursor = text_mark_get(txt, c->sel->cursor);
- view_cursors_to(c, cursor);
+ size_t pos = text_mark_get(txt, c->sel->cursor);
+ view_cursors_to(c, pos);
}
Filerange view_cursors_selection_get(Cursor *c) {
@@ -1287,12 +1287,13 @@ Filerange view_cursors_selection_get(Cursor *c) {
void view_cursors_selection_set(Cursor *c, const Filerange *r) {
if (!text_range_valid(r))
return;
- if (!c->sel)
- c->sel = view_selections_new(c->view);
- if (!c->sel)
+ if (!c->sel && !(c->sel = view_selections_new(c->view)))
return;
view_selections_set(c->sel, r);
+ size_t pos = view_cursors_pos(c);
+ if (!text_range_contains(r, pos))
+ view_cursors_selection_sync(c);
}
Selection *view_selections_new(View *view) {