From 2edabde9193d301ed0db14ac967d8b5503af7d8c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 21 Aug 2021 20:33:15 +1000 Subject: [PATCH] Do not go through some temporary selections for indent/deindent This does not seem necessary and simplifies the logic --- src/normal.cc | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index f8097645..cba92d0e 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1182,24 +1182,17 @@ void indent(Context& context, NormalParams params) String indent = indent_width == 0 ? String{'\t', count} : String{' ', indent_width * count}; auto& buffer = context.buffer(); - Vector sels; LineCount last_line = 0; for (auto& sel : context.selections()) { for (auto line = std::max(last_line, sel.min().line); line < sel.max().line+1; ++line) { if (indent_empty or buffer[line].length() > 1) - sels.emplace_back(line, line); + buffer.insert(line, indent); } // avoid reindenting the same line if multiple selections are on it last_line = sel.max().line+1; } - if (not sels.empty()) - { - ScopedEdition edition(context); - SelectionList selections{buffer, std::move(sels)}; - selections.insert(indent, InsertMode::Insert); - } } template @@ -1212,8 +1205,7 @@ void deindent(Context& context, NormalParams params) indent_width = tabstop; indent_width = indent_width * count; - const auto& buffer = context.buffer(); - Vector sels; + auto& buffer = context.buffer(); LineCount last_line = 0; for (auto& sel : context.selections()) { @@ -1232,12 +1224,12 @@ void deindent(Context& context, NormalParams params) else { if (deindent_incomplete and width != 0) - sels.emplace_back(line, BufferCoord{line, column-1}); + buffer.erase(line, BufferCoord{line, column}); break; } if (width >= indent_width) { - sels.emplace_back(line, BufferCoord{line, column}); + buffer.erase(line, BufferCoord{line, column+1}); break; } } @@ -1245,12 +1237,6 @@ void deindent(Context& context, NormalParams params) // avoid reindenting the same line if multiple selections are on it last_line = sel.max().line + 1; } - if (not sels.empty()) - { - ScopedEdition edition(context); - SelectionList selections{context.buffer(), std::move(sels)}; - selections.erase(); - } } template