From 892596f8affa5451ab0839ef57b9cb7bf0e6d037 Mon Sep 17 00:00:00 2001 From: Marcel Rodrigues Date: Tue, 24 Mar 2015 16:18:22 -0300 Subject: Implement 'o' in visual mode: go to other end of selection. --- vis.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'vis.c') diff --git a/vis.c b/vis.c index 52974b8..7dd6f06 100644 --- a/vis.c +++ b/vis.c @@ -448,6 +448,8 @@ static void movement_key(const Arg *arg); static void movement(const Arg *arg); /* let the current operator affect the range indicated by the text object arg->i */ static void textobj(const Arg *arg); +/* move to the other end of selected text */ +static void selection_end(const Arg *arg); /* use register indicated by arg->i for the current operator */ static void reg(const Arg *arg); /* perform a movement to mark arg->i */ @@ -958,6 +960,20 @@ static void textobj(const Arg *arg) { action_do(&action); } +static void selection_end(const Arg *arg) { + size_t pos = window_cursor_get(vis->win->win); + Filerange sel = window_selection_get(vis->win->win); + if (pos == sel.start) { + pos = text_char_prev(vis->win->text, sel.end); + } else { + pos = sel.start; + sel.start = text_char_prev(vis->win->text, sel.end); + sel.end = pos; + } + window_selection_set(vis->win->win, &sel); + window_cursor_to(vis->win->win, pos); +} + static void reg(const Arg *arg) { action.reg = &vis->registers[arg->i]; } -- cgit v1.2.3