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
This commit is contained in:
parent
d1ac4dbff3
commit
ae6ee02cb2
|
@ -764,7 +764,6 @@ void insert_output(Context& context, NormalParams params)
|
||||||
auto& selections = context.selections();
|
auto& selections = context.selections();
|
||||||
auto& buffer = context.buffer();
|
auto& buffer = context.buffer();
|
||||||
const size_t old_main = selections.main_index();
|
const size_t old_main = selections.main_index();
|
||||||
Vector<BufferRange> ins_range;
|
|
||||||
|
|
||||||
selections.for_each([&](size_t index, Selection& sel) {
|
selections.for_each([&](size_t index, Selection& sel) {
|
||||||
selections.set_main_index(index);
|
selections.set_main_index(index);
|
||||||
|
@ -772,16 +771,13 @@ void insert_output(Context& context, NormalParams params)
|
||||||
cmdline, context, content(context.buffer(), sel),
|
cmdline, context, content(context.buffer(), sel),
|
||||||
ShellManager::Flags::WaitForStdout);
|
ShellManager::Flags::WaitForStdout);
|
||||||
|
|
||||||
|
auto& min = sel.min();
|
||||||
|
auto& max = sel.max();
|
||||||
auto range = 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);
|
min = range.begin;
|
||||||
|
max = range.end > range.begin ? buffer.char_prev(range.end) : range.begin;
|
||||||
});
|
});
|
||||||
|
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<Vector>(), old_main);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user