From 85b78dda2e29d70b620836b04224b104426bdbae Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Thu, 22 Jul 2021 16:12:18 +0300 Subject: [PATCH] src: Select the data inserted by `!` and `` Closes #1468 --- doc/pages/keys.asciidoc | 4 ++-- src/normal.cc | 11 +++++++++-- src/selection.cc | 3 ++- src/selection.hh | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/pages/keys.asciidoc b/doc/pages/keys.asciidoc index 5f5c0e4aa9..e117b532bb 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 ca7063fd28..15f072113d 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -765,6 +765,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); @@ -772,10 +773,16 @@ void insert_output(Context& context, NormalParams params) cmdline, context, content(context.buffer(), sel), ShellManager::Flags::WaitForStdout); - insert(buffer, sel, paste_pos(buffer, sel, mode, false), out); + auto range = insert(buffer, sel, paste_pos(buffer, sel, mode, false), out); + 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 d408ddfd9c..cbf9bef28d 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -399,11 +399,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, BufferCoord pos, StringView content) +BufferRange insert(Buffer& buffer, Selection& sel, BufferCoord pos, StringView content) { auto range = buffer.insert(pos, 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 1aebe41f80..43ea412b79 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -75,7 +75,7 @@ void merge_overlapping_selections(Vector& selections, size_t& main); void clamp_selections(Vector& sel, const Buffer& buffer); void replace(Buffer& buffer, Selection& sel, StringView content); -void insert(Buffer& buffer, Selection& sel, BufferCoord pos, StringView content); +BufferRange insert(Buffer& buffer, Selection& sel, BufferCoord pos, StringView content); struct SelectionList {