summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-06-10 13:30:37 +0100
committerMaxime Coste <frrrwww@gmail.com>2014-06-10 13:30:37 +0100
commite6a97804908eae3795f84b199eff5c4a2b668909 (patch)
tree975c993910a557c21e7f6bfe030d9a937221bbb3 /src
parent3791e74743c65f384893207d91f693a5c33343cd (diff)
Fix tabs-to-spaces an spaces-to-tabs with the selection refactor
Diffstat (limited to 'src')
-rw-r--r--src/normal.cc26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/normal.cc b/src/normal.cc
index 0e4498c5..316f657f 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -1105,23 +1105,24 @@ void tabs_to_spaces(Context& context, int ts)
auto& buffer = context.buffer();
const CharCount opt_tabstop = context.options()["tabstop"].get<int>();
const CharCount tabstop = ts == 0 ? opt_tabstop : ts;
+ std::vector<Selection> tabs;
+ std::vector<String> spaces;
for (auto& sel : context.selections())
{
for (auto it = buffer.iterator_at(sel.min()),
- end = buffer.iterator_at(sel.max())+1; it != end;)
+ end = buffer.iterator_at(sel.max())+1; it != end; ++it)
{
if (*it == '\t')
{
CharCount col = get_column(buffer, opt_tabstop, it.coord());
CharCount end_col = (col / tabstop + 1) * tabstop;
- it = buffer.erase(it, it+1);
- it = buffer.insert(it, String{ ' ', end_col - col }) + (int)(end_col - col);
- end = buffer.iterator_at(sel.max())+1;
+ tabs.push_back({ it.coord() });
+ spaces.push_back(String{ ' ', end_col - col });
}
- else
- ++it;
}
}
+ if (not tabs.empty())
+ SelectionList{ buffer, std::move(tabs) }.insert(spaces, InsertMode::Replace);
}
void spaces_to_tabs(Context& context, int ts)
@@ -1129,6 +1130,7 @@ void spaces_to_tabs(Context& context, int ts)
auto& buffer = context.buffer();
const CharCount opt_tabstop = context.options()["tabstop"].get<int>();
const CharCount tabstop = ts == 0 ? opt_tabstop : ts;
+ std::vector<Selection> spaces;
for (auto& sel : context.selections())
{
for (auto it = buffer.iterator_at(sel.min()),
@@ -1144,20 +1146,16 @@ void spaces_to_tabs(Context& context, int ts)
++spaces_end;
++col;
}
-
if ((col % tabstop) == 0)
- {
- it = buffer.erase(spaces_beg, spaces_end);
- it = buffer.insert(it, "\t") + 1;
- end = buffer.iterator_at(sel.max())+1;
- }
- else
- it = spaces_end;
+ spaces.push_back({spaces_beg.coord(), (spaces_end-1).coord()});
+ it = spaces_end;
}
else
++it;
}
}
+ if (not spaces.empty())
+ SelectionList{ buffer, std::move(spaces) }.insert("\t"_str, InsertMode::Replace);
}
void undo(Context& context, int)