From dc9635a247e0d3d537ac5b62e7948d24e531b70a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 31 Dec 2012 13:44:01 +0100 Subject: [PATCH] Fix join on last line (it appended a trailing space) --- src/main.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.cc b/src/main.cc index 26ad5ba3..51dbe224 100644 --- a/src/main.cc +++ b/src/main.cc @@ -268,11 +268,21 @@ void do_join(Context& context) { Editor& editor = context.editor(); 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_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.select(sels); } void do_indent(Context& context)