Fix join on last line (it appended a trailing space)

This commit is contained in:
Maxime Coste 2012-12-31 13:44:01 +01:00
parent fe363094cf
commit dc9635a247

View File

@ -268,11 +268,21 @@ void do_join(Context& context)
{ {
Editor& editor = context.editor(); Editor& editor = context.editor();
DynamicSelectionList sels{editor.buffer(), editor.selections()}; DynamicSelectionList sels{editor.buffer(), editor.selections()};
auto restore_sels = on_scope_end([&]{ editor.select((SelectionList)std::move(sels)); });
editor.select(select_whole_lines); editor.select(select_whole_lines);
editor.select(select_to_eol, SelectMode::Extend); editor.select(select_to_eol, SelectMode::Extend);
editor.multi_select(std::bind(select_all_matches, _1, "\n\\h*")); editor.multi_select([](const Selection& sel)
{
SelectionList res = select_all_matches(sel, "\n\\h*");
// remove last end of line if selected
assert(std::is_sorted(res.begin(), res.end(),
[](const Selection& lhs, const Selection& rhs)
{ return lhs.begin() < rhs.begin(); }));
if (not res.empty() and res.back().end() == sel.buffer().end())
res.pop_back();
return res;
});
editor.insert(" ", InsertMode::Replace); editor.insert(" ", InsertMode::Replace);
editor.select(sels);
} }
void do_indent(Context& context) void do_indent(Context& context)