diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-03-15 14:22:42 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-03-15 14:22:42 +0100 |
| commit | 5e88b7fe283e66c3afebc4f287fbea72be41374e (patch) | |
| tree | acb1bac6230defeb065306784e86529add48ebc6 /src | |
| parent | 0c4addb40cfdbdc1590b5311eda82bbc607f1030 (diff) | |
move BufferIterator on_{insert,erase} as DynamicSelectionList implementation detail
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer.hh | 5 | ||||
| -rw-r--r-- | src/buffer_iterator.inl.hh | 46 | ||||
| -rw-r--r-- | src/dynamic_selection_list.cc | 44 |
3 files changed, 49 insertions, 46 deletions
diff --git a/src/buffer.hh b/src/buffer.hh index 28f550a2..f29ca77f 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -58,15 +58,14 @@ public: BufferIterator operator++ (int); BufferIterator operator-- (int); + BufferIterator& operator=(const BufferCoord& coord); + void clamp(bool avoid_eol); bool is_begin() const; bool is_end() const; bool is_valid() const; - void on_insert(const BufferCoord& begin, const BufferCoord& end); - void on_erase(const BufferCoord& begin, const BufferCoord& end); - const Buffer& buffer() const; const BufferCoord& coord() const { return m_coord; } LineCount line() const { return m_coord.line; } diff --git a/src/buffer_iterator.inl.hh b/src/buffer_iterator.inl.hh index 717da898..90d17219 100644 --- a/src/buffer_iterator.inl.hh +++ b/src/buffer_iterator.inl.hh @@ -70,45 +70,6 @@ inline bool BufferIterator::operator>=(const BufferIterator& iterator) const return (m_coord >= iterator.m_coord); } -inline void BufferIterator::on_insert(const BufferCoord& begin, - const BufferCoord& end) -{ - if (m_coord < begin) - return; - - if (begin.line == m_coord.line) - m_coord.column = end.column + m_coord.column - begin.column; - m_coord.line += end.line - begin.line; - - assert(is_valid()); -} - -inline void BufferIterator::on_erase(const BufferCoord& begin, - const BufferCoord& end) -{ - if (m_coord < begin) - return; - - if (m_coord <= end) - { - m_coord = begin; - if (is_end()) - operator--(); - } - else - { - if (end.line == m_coord.line) - { - m_coord.line = begin.line; - m_coord.column = begin.column + m_coord.column - end.column; - } - else - m_coord.line -= end.line - begin.line; - } - assert(is_valid()); -} - - inline char BufferIterator::operator*() const { return m_buffer->m_lines[m_coord.line].content[m_coord.column]; @@ -212,6 +173,13 @@ inline BufferIterator BufferIterator::operator--(int) return save; } +inline BufferIterator& BufferIterator::operator=(const BufferCoord& coord) +{ + m_coord = coord; + assert(is_valid()); + return *this; +} + inline bool BufferIterator::is_begin() const { assert(m_buffer); 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); } } |
