diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2014-05-14 20:56:27 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2014-05-14 20:56:49 +0100 |
| commit | 4e280977a2fcd7ca423b5909b435b896b256cdaf (patch) | |
| tree | caf34647ab26f749f5c63f5af71f34302bc5e261 /src/selection.cc | |
| parent | c3f4ef9ba2e8ca58acc6cf56e552341a5af62f5d (diff) | |
Iterate in reversed order on selections when modifing buffer
This way, update only needs to be called once everything is done
as we always modify after the next selection to be used.
Diffstat (limited to 'src/selection.cc')
| -rw-r--r-- | src/selection.cc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/selection.cc b/src/selection.cc index 746253f9..1e8356ab 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -188,5 +188,31 @@ void SelectionList::sort_and_merge_overlapping() std::stable_sort(begin(), end(), compare_selections); merge_overlapping(overlaps); } +namespace +{ + +inline void _avoid_eol(const Buffer& buffer, ByteCoord& coord) +{ + const auto column = coord.column; + const auto& line = buffer[coord.line]; + if (column != 0 and column == line.length() - 1) + coord.column = line.byte_count_to(line.char_length() - 2); +} + + +inline void _avoid_eol(const Buffer& buffer, Selection& sel) +{ + _avoid_eol(buffer, sel.anchor()); + _avoid_eol(buffer, sel.cursor()); +} + +} + +void SelectionList::avoid_eol() +{ + update(); + for (auto& sel : m_selections) + _avoid_eol(buffer(), sel); +} } |
