From a404886fe21432159bb9b759b12b69a446fad551 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 25 Sep 2014 19:26:27 +0100 Subject: [PATCH] line joining will only join selected lines if selection span multiples ones Fixes #133 --- src/normal.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index 1de74b977..9b6ea48e0 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -691,10 +691,12 @@ void join_select_spaces(Context& context, int) std::vector selections; for (auto& sel : context.selections()) { - for (LineCount line = sel.min().line; line <= sel.max().line; ++line) + const LineCount min_line = sel.min().line; + const LineCount max_line = sel.max().line; + auto end_line = std::min(buffer.line_count()-1, + max_line + (min_line == max_line ? 1 : 0)); + for (LineCount line = min_line; line < end_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);