summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-05-19 18:59:14 +0100
committerMaxime Coste <frrrwww@gmail.com>2014-05-19 18:59:14 +0100
commitb29cae4d16077c6121e5d4cff00416fd98dfc60c (patch)
treecbaaa2c6fdc5c955eb1225e8b6d3b613dcbaaf3b /src
parent03e5264df44794c942a5b1d45be3acd546819d5a (diff)
Remove duplicated logic and fix insert in Replace mode
Diffstat (limited to 'src')
-rw-r--r--src/normal.cc33
1 files changed, 4 insertions, 29 deletions
diff --git a/src/normal.cc b/src/normal.cc
index 0e2d3b38..2e68f8cd 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -63,30 +63,6 @@ BufferIterator prepare_insert(Buffer& buffer, const Selection& sel)
}
template<InsertMode mode>
-void insert(Buffer& buffer, SelectionList& selections, const String& str)
-{
- for (auto& sel : reversed(selections))
- {
- auto pos = prepare_insert<mode>(buffer, sel);
- pos = buffer.insert(pos, str);
- if (mode == InsertMode::Replace)
- {
- if (pos == buffer.end())
- --pos;
- sel.anchor() = pos.coord();
- sel.cursor() = str.empty() ?
- pos.coord() : (pos + str.byte_count_to(str.char_length() - 1)).coord();
- }
- }
- if (mode == InsertMode::Replace)
- selections.update_timestamp();
- else
- selections.update();
- selections.avoid_eol();
- buffer.check_invariant();
-}
-
-template<InsertMode mode>
void insert(Buffer& buffer, SelectionList& selections, memoryview<String> strings)
{
if (strings.empty())
@@ -102,16 +78,15 @@ void insert(Buffer& buffer, SelectionList& selections, memoryview<String> string
{
if (pos == buffer.end())
--pos;
+ selections.update();
sel.anchor() = pos.coord();
sel.cursor() = (str.empty() ?
pos : pos + str.byte_count_to(str.char_length() - 1)).coord();
}
}
- if (mode == InsertMode::Replace)
- selections.update_timestamp();
- else
- selections.update();
+ selections.update();
selections.avoid_eol();
+ selections.check_invariant();
buffer.check_invariant();
}
@@ -788,7 +763,7 @@ void join_select_spaces(Context& context, int)
return;
context.selections() = selections;
ScopedEdition edition(context);
- insert<InsertMode::Replace>(buffer, context.selections(), " ");
+ insert<InsertMode::Replace>(buffer, context.selections(), " "_str);
}
void join(Context& context, int param)