From 2ce403c9586150ac7814e61dbbe798a17fe75d26 Mon Sep 17 00:00:00 2001 From: Marcel Rodrigues Date: Tue, 24 Mar 2015 11:52:14 -0300 Subject: [PATCH] Implement 'o' in visual mode: go to other end of selection. --- config.def.h | 1 + vis.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/config.def.h b/config.def.h index a0876be..30f6e41 100644 --- a/config.def.h +++ b/config.def.h @@ -447,6 +447,7 @@ static KeyBinding vis_mode_visual[] = { { { NONE('r') }, operator, { .i = OP_CHANGE } }, { { NONE('s') }, operator, { .i = OP_CHANGE } }, { { NONE('J') }, operator, { .i = OP_JOIN } }, + { { NONE('o') }, movement, { .i = MOVE_SELECTION_HANDLE} }, { /* empty last element, array terminator */ }, }; diff --git a/vis.c b/vis.c index 52974b8..c3343c1 100644 --- a/vis.c +++ b/vis.c @@ -254,6 +254,7 @@ enum { MOVE_WINDOW_LINE_TOP, MOVE_WINDOW_LINE_MIDDLE, MOVE_WINDOW_LINE_BOTTOM, + MOVE_SELECTION_HANDLE, }; /** movements which can be used besides the one in text-motions.h and window.h */ @@ -287,6 +288,8 @@ static size_t window_lines_top(const Arg *arg); static size_t window_lines_middle(const Arg *arg); /* goto the action.count-th line from bottom of the focused window */ static size_t window_lines_bottom(const Arg *arg); +/* goto the other end of selected text */ +static size_t move_selection_handle(const Arg *arg); static Movement moves[] = { [MOVE_LINE_UP] = { .win = window_line_up }, @@ -335,6 +338,7 @@ static Movement moves[] = { [MOVE_WINDOW_LINE_TOP] = { .cmd = window_lines_top, .type = LINEWISE|JUMP }, [MOVE_WINDOW_LINE_MIDDLE] = { .cmd = window_lines_middle, .type = LINEWISE|JUMP }, [MOVE_WINDOW_LINE_BOTTOM] = { .cmd = window_lines_bottom, .type = LINEWISE|JUMP }, + [MOVE_SELECTION_HANDLE] = { .cmd = move_selection_handle, .type = CHARWISE }, }; /* these can be passed as int argument to textobj(&(const Arg){ .i = TEXT_OBJ_* }) */ @@ -806,6 +810,20 @@ static size_t window_lines_bottom(const Arg *arg) { return window_screenline_goto(vis->win->win, vis->win->height - action.count); } +static size_t move_selection_handle(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 = sel.end - 1; + } else { + pos = sel.start; + sel.start = sel.end - 1; + sel.end = pos; + } + window_selection_set(vis->win->win, &sel); + return pos; +} + /** key bindings functions of type: void (*func)(const Arg*) */ static void jumplist(const Arg *arg) { -- 2.3.4