From f38cdb2d38357f8f01a766ea21cb30661a0d99e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 31 Jul 2015 13:34:27 +0200 Subject: vis: cleanup handling of charwise/linewise motions Also text objects in visual mode should now work better. --- view.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'view.c') 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) { -- cgit v1.2.3