diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-07-31 13:34:27 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-07-31 15:39:12 +0200 |
| commit | f38cdb2d38357f8f01a766ea21cb30661a0d99e8 (patch) | |
| tree | fef5d07b8c47ad3a7c7f9d18e957226cafc53833 /view.c | |
| parent | 45994302f232fc4b13fde1b85f512f9238d36613 (diff) | |
| download | vis-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.c | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -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) { |
