From c8e7be3107f39c32cf503db45a73b165659406c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Mon, 28 Mar 2016 23:13:57 +0200 Subject: 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. --- sam.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sam.c b/sam.c index 0e94b8c..e8b083b 100644 --- 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; } -- cgit v1.2.3