summaryrefslogtreecommitdiff
path: root/src/normal.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2022-10-19 20:15:54 +1100
committerMaxime Coste <mawww@kakoune.org>2022-10-19 20:16:09 +1100
commitae6ee02cb210c4778868316cbd4fa2d5e194a903 (patch)
treec425fa12e53e291a51a8abf8ea0a66d39b5267de /src/normal.cc
parentd1ac4dbff364b90ecdbfe989ba674c53809eb757 (diff)
Refactor insert_output command to avoid intermediate vector
This is like a paste with a different source, so the same logic should work. This means we now correctly fix overflowing selections. Fixes #4750
Diffstat (limited to 'src/normal.cc')
-rw-r--r--src/normal.cc14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/normal.cc b/src/normal.cc
index 12843565..5f0512d7 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -764,7 +764,6 @@ void insert_output(Context& context, NormalParams params)
auto& selections = context.selections();
auto& buffer = context.buffer();
const size_t old_main = selections.main_index();
- Vector<BufferRange> ins_range;
selections.for_each([&](size_t index, Selection& sel) {
selections.set_main_index(index);
@@ -772,16 +771,13 @@ void insert_output(Context& context, NormalParams params)
cmdline, context, content(context.buffer(), sel),
ShellManager::Flags::WaitForStdout);
+ auto& min = sel.min();
+ auto& max = sel.max();
auto range = insert(buffer, sel, paste_pos(buffer, sel, mode, false), out);
- ins_range.push_back(range);
+ min = range.begin;
+ max = range.end > range.begin ? buffer.char_prev(range.end) : range.begin;
});
-
- 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<Vector>(), old_main);
+ selections.set_main_index(old_main);
});
}