summaryrefslogtreecommitdiff
path: root/src/normal.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-01-03 20:41:47 +0000
committerMaxime Coste <frrrwww@gmail.com>2014-01-03 20:41:47 +0000
commit6c4c32eb59683bb9d975940cb0923c08fe4dbfc0 (patch)
tree64b3a1d7c170a58c73799a12e8048966f808047e /src/normal.cc
parent25e6c1cc39e7177bde74ef83dc53cd20847321df (diff)
Rewrite join_select_spaces
Stop using regex for selecting spaces at the begining of the line
Diffstat (limited to 'src/normal.cc')
-rw-r--r--src/normal.cc29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/normal.cc b/src/normal.cc
index 2426d9a8..be2703ca 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -725,19 +725,26 @@ void split_lines(Context& context, int)
void join_select_spaces(Context& context, int)
{
- select(context, select_whole_lines);
- select<SelectMode::Extend>(context, select_to_eol);
auto& buffer = context.buffer();
- auto& selections = context.selections();
- select_all_matches(buffer, selections, Regex{"(\n\\h*)+"});
- // remove last end of line if selected
- kak_assert(std::is_sorted(selections.begin(), selections.end(),
- [](const Selection& lhs, const Selection& rhs)
- { return lhs.min() < rhs.min(); }));
- if (not selections.empty() and selections.back().max() == buffer.back_coord())
- selections.pop_back();
+ SelectionList selections;
+ for (auto& sel : context.selections())
+ {
+ for (LineCount line = sel.min().line; line <= sel.max().line; ++line)
+ {
+ if (line == buffer.line_count() - 1)
+ continue;
+ auto begin = buffer.iterator_at({line, buffer[line].length()-1});
+ auto end = begin+1;
+ skip_while(end, buffer.end(), is_horizontal_blank);
+ selections.push_back({begin.coord(), (end-1).coord()});
+ }
+ }
+ if (selections.empty())
+ return;
+ selections.sort_and_merge_overlapping();
+ context.selections() = selections;
ScopedEdition edition(context);
- insert<InsertMode::Replace>(buffer, selections, " ");
+ insert<InsertMode::Replace>(buffer, context.selections(), " ");
}
void join(Context& context, int param)