summaryrefslogtreecommitdiff
path: root/src/normal.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-11-28 13:22:54 +0000
committerMaxime Coste <frrrwww@gmail.com>2014-11-28 13:22:54 +0000
commitda9f688f37685b7e07f6e710eb64d4376e66562b (patch)
treeb4ff3d54185e96f756dae8d96ceaf62dad9d1e54 /src/normal.cc
parent6902301674350d7f31c39c271636e65709fbfb6d (diff)
Fix indent/deindent when multiple selections are on same line
Diffstat (limited to 'src/normal.cc')
-rw-r--r--src/normal.cc11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/normal.cc b/src/normal.cc
index 3c4528e0..e713d73d 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -768,13 +768,16 @@ void indent(Context& context, int)
auto& buffer = context.buffer();
std::vector<Selection> sels;
+ LineCount last_line = 0;
for (auto& sel : context.selections())
{
- for (auto line = sel.min().line; line < sel.max().line+1; ++line)
+ 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.push_back({line, line});
}
+ // avoid reindenting the same line if multiple selections are on it
+ last_line = sel.max().line+1;
}
if (not sels.empty())
{
@@ -794,9 +797,11 @@ void deindent(Context& context, int)
auto& buffer = context.buffer();
std::vector<Selection> sels;
+ LineCount last_line = 0;
for (auto& sel : context.selections())
{
- for (auto line = sel.min().line; line < sel.max().line+1; ++line)
+ for (auto line = std::max(sel.min().line, last_line);
+ line < sel.max().line+1; ++line)
{
CharCount width = 0;
auto content = buffer[line];
@@ -820,6 +825,8 @@ void deindent(Context& context, int)
}
}
}
+ // avoid reindenting the same line if multiple selections are on it
+ last_line = sel.max().line + 1;
}
if (not sels.empty())
{