From 90b5fdbcf78eee5cdb933c234d79a1aaa2bbf867 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Mon, 1 Feb 2016 22:47:28 +0100 Subject: [PATCH] Improve cursor position after :substitute command --- vis-cmds.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vis-cmds.c b/vis-cmds.c index 9b2c887..3f612f4 100644 --- a/vis-cmds.c +++ b/vis-cmds.c @@ -14,6 +14,7 @@ #include "vis-core.h" #include "text-util.h" #include "text-motions.h" +#include "text-objects.h" #include "util.h" enum CmdOpt { /* option flags for command definitions */ @@ -538,7 +539,7 @@ static bool cmd_read(Vis *vis, Filerange *range, enum CmdOpt opt, const char *ar static bool cmd_substitute(Vis *vis, Filerange *range, enum CmdOpt opt, const char *argv[]) { char pattern[255]; if (!text_range_valid(range)) - *range = (Filerange){ .start = 0, .end = text_size(vis->win->file->text) }; + *range = text_object_line(vis->win->file->text, view_cursor_get(vis->win->view)); snprintf(pattern, sizeof pattern, "s%s", argv[1]); return cmd_filter(vis, range, opt, (const char*[]){ argv[0], "sed", pattern, NULL}); } @@ -847,12 +848,11 @@ static bool cmd_filter(Vis *vis, Filerange *range, enum CmdOpt opt, const char * int status = vis_pipe(vis, &filter, range, argv, read_stdout, read_stderr); - if (range->start != EPOS) - view_cursor_to(view, range->start); - if (status == 0) { - if (text_range_valid(range)) + if (text_range_valid(range)) { text_delete_range(txt, range); + view_cursor_to(view, range->start); + } text_snapshot(txt); } else { /* make sure we have somehting to undo */ -- 2.11.4.GIT