vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 2160b1393b9e34e4da5e364b8a1307492339e6d8 parent 4835649b460769c6158fcc3c968e9bd3e52d181e Author: Marc André Tanner <mat@brain-dump.org> Date: Mon, 28 Mar 2016 23:13:57 +0200 sam: remove old cursor/selection before executing command Because duplicated cursors are no longer allowed we have to remove the old cursors before, not after executing the sam command. Otherwise commands like g/foo/ which re-create the same selection fail. Diffstat:
| M | sam.c | | | 13 | ++++++++++++- |
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/sam.c b/sam.c @@ -729,6 +729,8 @@ static bool cmd_select(Vis *vis, Win *win, Command *cmd, Filerange *range) { View *view = win->view; Text *txt = win->file->text; bool multiple_cursors = view_cursors_multiple(view); + size_t pos = view_cursor_get(view); + Cursor *cursor = NULL; for (Cursor *c = view_cursors(view), *next; c; c = next) { next = view_cursors_next(c); Filerange sel; @@ -743,9 +745,18 @@ static bool cmd_select(Vis *vis, Win *win, Command *cmd, Filerange *range) { } else { sel = text_range_new(0, text_size(txt)); } + if (!view_cursors_dispose(c)) { + cursor = view_cursors_new(view, text_size(txt)+1); + view_cursors_dispose(c); + } ret &= sam_execute(vis, win, cmd->cmd, &sel); - view_cursors_dispose(c); } + + if (cursor && !view_cursors_dispose(cursor)) { + view_cursors_selection_clear(cursor); + view_cursors_to(cursor, pos); + } + return ret; }