aboutsummaryrefslogtreecommitdiff
path: root/view.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-07-31 13:34:27 +0200
committerMarc André Tanner <mat@brain-dump.org>2015-07-31 15:39:12 +0200
commitf38cdb2d38357f8f01a766ea21cb30661a0d99e8 (patch)
treefef5d07b8c47ad3a7c7f9d18e957226cafc53833 /view.c
parent45994302f232fc4b13fde1b85f512f9238d36613 (diff)
downloadvis-f38cdb2d38357f8f01a766ea21cb30661a0d99e8.tar.gz
vis-f38cdb2d38357f8f01a766ea21cb30661a0d99e8.tar.xz
vis: cleanup handling of charwise/linewise motions
Also text objects in visual mode should now work better.
Diffstat (limited to 'view.c')
-rw-r--r--view.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/view.c b/view.c
index ff3ab42..6d62dde 100644
--- a/view.c
+++ b/view.c
@@ -1005,14 +1005,20 @@ void view_cursors_selection_clear(Cursor *c) {
void view_cursors_selection_swap(Cursor *c) {
if (!c->sel)
return;
- Text *txt = c->view->text;
- bool left_extending = c->mark == c->sel->cursor;
view_selections_swap(c->sel);
- c->mark = c->sel->cursor;
- size_t pos = text_mark_get(txt, c->mark);
- if (left_extending)
- pos = text_char_prev(txt, pos);
- cursor_to(c, pos);
+ view_cursors_selection_sync(c);
+}
+
+void view_cursors_selection_sync(Cursor *c) {
+ if (!c->sel)
+ return;
+ Text *txt = c->view->text;
+ size_t anchor = text_mark_get(txt, c->sel->anchor);
+ size_t cursor = text_mark_get(txt, c->sel->cursor);
+ bool right_extending = anchor < cursor;
+ if (right_extending)
+ cursor = text_char_prev(txt, cursor);
+ cursor_to(c, cursor);
}
Filerange view_cursors_selection_get(Cursor *c) {