summaryrefslogtreecommitdiff
path: root/src/dynamic_selection_list.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-03-15 14:22:42 +0100
committerMaxime Coste <frrrwww@gmail.com>2013-03-15 14:22:42 +0100
commit5e88b7fe283e66c3afebc4f287fbea72be41374e (patch)
treeacb1bac6230defeb065306784e86529add48ebc6 /src/dynamic_selection_list.cc
parent0c4addb40cfdbdc1590b5311eda82bbc607f1030 (diff)
move BufferIterator on_{insert,erase} as DynamicSelectionList implementation detail
Diffstat (limited to 'src/dynamic_selection_list.cc')
-rw-r--r--src/dynamic_selection_list.cc44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/dynamic_selection_list.cc b/src/dynamic_selection_list.cc
index b684ec56..647bf22b 100644
--- a/src/dynamic_selection_list.cc
+++ b/src/dynamic_selection_list.cc
@@ -72,14 +72,50 @@ void DynamicSelectionList::check_invariant() const
#endif
}
+static void update_insert(BufferIterator& it,
+ const BufferCoord& begin, const BufferCoord& end)
+{
+ BufferCoord coord = it.coord();
+ if (coord < begin)
+ return;
+
+ if (begin.line == coord.line)
+ coord.column = end.column + coord.column - begin.column;
+ coord.line += end.line - begin.line;
+
+ it = coord;
+}
+
+static void update_erase(BufferIterator& it,
+ const BufferCoord& begin, const BufferCoord& end)
+{
+ BufferCoord coord = it.coord();
+ if (coord < begin)
+ return;
+
+ if (coord <= end)
+ coord = it.buffer().clamp(begin);
+ else
+ {
+ if (end.line == coord.line)
+ {
+ coord.line = begin.line;
+ coord.column = begin.column + coord.column - end.column;
+ }
+ else
+ coord.line -= end.line - begin.line;
+ }
+ it = coord;
+}
+
void DynamicSelectionList::on_insert(const BufferIterator& begin, const BufferIterator& end)
{
const BufferCoord begin_coord{begin.coord()};
const BufferCoord end_coord{end.coord()};
for (auto& sel : *this)
{
- sel.first().on_insert(begin_coord, end_coord);
- sel.last().on_insert(begin_coord, end_coord);
+ update_insert(sel.first(), begin_coord, end_coord);
+ update_insert(sel.last(), begin_coord, end_coord);
}
}
@@ -89,8 +125,8 @@ void DynamicSelectionList::on_erase(const BufferIterator& begin, const BufferIte
const BufferCoord end_coord{end.coord()};
for (auto& sel : *this)
{
- sel.first().on_erase(begin_coord, end_coord);
- sel.last().on_erase(begin_coord, end_coord);
+ update_erase(sel.first(), begin_coord, end_coord);
+ update_erase(sel.last(), begin_coord, end_coord);
}
}