diff --git a/doc/pages/keys.asciidoc b/doc/pages/keys.asciidoc index 1e8b295634..7c346dc82b 100644 --- a/doc/pages/keys.asciidoc +++ b/doc/pages/keys.asciidoc @@ -374,10 +374,10 @@ The default command comes from the *|* register by default (See <*:: - append command output after each selection. + append and select command output after each selection. == Searching diff --git a/src/normal.cc b/src/normal.cc index 2b996e3cb4..d1d587c88d 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -645,6 +645,7 @@ void insert_output(Context& context, NormalParams params) auto& selections = context.selections(); auto& buffer = context.buffer(); const size_t old_main = selections.main_index(); + Vector ins_range; selections.for_each([&](size_t index, Selection& sel) { selections.set_main_index(index); @@ -652,10 +653,16 @@ void insert_output(Context& context, NormalParams params) cmdline, context, content(context.buffer(), sel), ShellManager::Flags::WaitForStdout); - insert(buffer, sel, out, mode); + auto range = insert(buffer, sel, out, mode); + ins_range.push_back(range); }); - selections.set_main_index(old_main); + selections.set(ins_range | transform([&buffer](auto& range) { + if (range.empty()) + return Selection{range.begin, range.end}; + return Selection{range.begin, + buffer.char_prev(range.end)}; + }) | gather(), old_main); }); } diff --git a/src/selection.cc b/src/selection.cc index 27a40156ea..1a8f871be8 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -432,11 +432,12 @@ void replace(Buffer& buffer, Selection& sel, StringView content) max = range.end > range.begin ? buffer.char_prev(range.end) : range.begin; } -void insert(Buffer& buffer, Selection& sel, StringView content, InsertMode mode) +BufferRange insert(Buffer& buffer, Selection& sel, StringView content, InsertMode mode) { auto range = buffer.insert(get_insert_pos(buffer, sel, mode), content); sel.anchor() = buffer.clamp(update_insert(sel.anchor(), range.begin, range.end)); sel.cursor() = buffer.clamp(update_insert(sel.cursor(), range.begin, range.end)); + return range; } void SelectionList::replace(ConstArrayView strings) diff --git a/src/selection.hh b/src/selection.hh index 5d6e742701..0a06899f4d 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -90,7 +90,7 @@ enum class InsertMode : unsigned BufferCoord get_insert_pos(const Buffer& buffer, const Selection& sel, InsertMode mode); void replace(Buffer& buffer, Selection& sel, StringView content); -void insert(Buffer& buffer, Selection& sel, StringView content, InsertMode mode); +BufferRange insert(Buffer& buffer, Selection& sel, StringView content, InsertMode mode); struct SelectionList