diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2014-05-12 13:59:21 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2014-05-13 19:01:27 +0100 |
| commit | 67a251ffd560d79e8337fef0aee8d8285d34355e (patch) | |
| tree | 852a301689b7612f958cda7728004b59aa47e335 /src/selection.cc | |
| parent | ddd8f8d392ae059298ffa6175165f6e224a009f9 (diff) | |
Pass a at_end param to BufferChangeListener::on_{insert,erase}
Diffstat (limited to 'src/selection.cc')
| -rw-r--r-- | src/selection.cc | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/src/selection.cc b/src/selection.cc index e1627a0c..0049689d 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -18,8 +18,8 @@ namespace { template<template <bool, bool> class UpdateFunc> -void on_buffer_change(const Buffer& buffer, SelectionList& sels, - ByteCoord begin, ByteCoord end, LineCount end_line) +void on_buffer_change(SelectionList& sels, + ByteCoord begin, ByteCoord end, bool at_end, LineCount end_line) { auto update_beg = std::lower_bound(sels.begin(), sels.end(), begin, [](const Selection& s, ByteCoord c) @@ -31,20 +31,20 @@ void on_buffer_change(const Buffer& buffer, SelectionList& sels, if (update_beg != update_only_line_beg) { // for the first one, we are not sure if min < begin - UpdateFunc<false, false>{}(buffer, update_beg->anchor(), begin, end); - UpdateFunc<false, false>{}(buffer, update_beg->cursor(), begin, end); + UpdateFunc<false, false>{}(update_beg->anchor(), begin, end, at_end); + UpdateFunc<false, false>{}(update_beg->cursor(), begin, end, at_end); } for (auto it = update_beg+1; it < update_only_line_beg; ++it) { - UpdateFunc<false, true>{}(buffer, it->anchor(), begin, end); - UpdateFunc<false, true>{}(buffer, it->cursor(), begin, end); + UpdateFunc<false, true>{}(it->anchor(), begin, end, at_end); + UpdateFunc<false, true>{}(it->cursor(), begin, end, at_end); } if (end.line > begin.line) { for (auto it = update_only_line_beg; it != sels.end(); ++it) { - UpdateFunc<true, true>{}(buffer, it->anchor(), begin, end); - UpdateFunc<true, true>{}(buffer, it->cursor(), begin, end); + UpdateFunc<true, true>{}(it->anchor(), begin, end, at_end); + UpdateFunc<true, true>{}(it->cursor(), begin, end, at_end); } } } @@ -52,8 +52,8 @@ void on_buffer_change(const Buffer& buffer, SelectionList& sels, template<bool assume_different_line, bool assume_greater_than_begin> struct UpdateInsert { - void operator()(const Buffer& buffer, ByteCoord& coord, - ByteCoord begin, ByteCoord end) const + void operator()(ByteCoord& coord, ByteCoord begin, ByteCoord end, + bool at_end) const { if (assume_different_line) kak_assert(begin.line < coord.line); @@ -69,15 +69,21 @@ struct UpdateInsert template<bool assume_different_line, bool assume_greater_than_begin> struct UpdateErase { - void operator()(const Buffer& buffer, ByteCoord& coord, - ByteCoord begin, ByteCoord end) const + void operator()(ByteCoord& coord, ByteCoord begin, ByteCoord end, + bool at_end) const { if (not assume_greater_than_begin and coord < begin) return; if (assume_different_line) kak_assert(end.line < coord.line); if (not assume_different_line and coord <= end) - coord = buffer.clamp(begin); + { + if (not at_end) + coord = begin; + else + coord = begin.column ? ByteCoord{begin.line, begin.column-1} + : ByteCoord{begin.line - 1}; + } else { if (not assume_different_line and end.line == coord.line) @@ -93,14 +99,14 @@ struct UpdateErase } -void SelectionList::update_insert(const Buffer& buffer, ByteCoord begin, ByteCoord end) +void SelectionList::update_insert(ByteCoord begin, ByteCoord end, bool at_end) { - on_buffer_change<UpdateInsert>(buffer, *this, begin, end, begin.line); + on_buffer_change<UpdateInsert>(*this, begin, end, at_end, begin.line); } -void SelectionList::update_erase(const Buffer& buffer, ByteCoord begin, ByteCoord end) +void SelectionList::update_erase(ByteCoord begin, ByteCoord end, bool at_end) { - on_buffer_change<UpdateErase>(buffer, *this, begin, end, end.line); + on_buffer_change<UpdateErase>(*this, begin, end, at_end, end.line); } void SelectionList::check_invariant() const |
