diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-12-11 19:51:59 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-12-13 18:50:27 +0100 |
| commit | cfd7ee049a7c668bb2269029d159b34d2014ece6 (patch) | |
| tree | dc8d3eef1af8318acde758de012db858d4c36e30 /src/selection.hh | |
| parent | e36bc74f431e2f98f049724536da86af9051811d (diff) | |
move selection updating code out of selection, to DynamicSelectionList
this avoids a lot of unnecessary (add|remove)_change_listener as
creating temporary Selections do not call that anymore.
Use can choose between a SelectionList which or a DynamicSelectionList
depending on wethear the buffer will be modified or not during the
selections lifetime.
Diffstat (limited to 'src/selection.hh')
| -rw-r--r-- | src/selection.hh | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/selection.hh b/src/selection.hh index 8ea0fa97..83246a9c 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -21,11 +21,17 @@ public: const BufferIterator& first() const { return m_first; } const BufferIterator& last() const { return m_last; } + bool operator== (const Range& other) const + { + return m_first == other.m_first and m_last == other.m_last; + } + // returns min(first, last) BufferIterator begin() const; // returns max(first, last) + 1 BufferIterator end() const; + void check_invariant() const; private: BufferIterator m_first; BufferIterator m_last; @@ -40,33 +46,19 @@ inline bool overlaps(const Range& lhs, const Range& rhs) using CaptureList = std::vector<String>; // A selection is a Range, associated with a CaptureList -// that updates itself when the buffer it points to gets modified. -struct Selection : public Range, public BufferChangeListener +struct Selection : public Range { Selection(const BufferIterator& first, const BufferIterator& last, - CaptureList captures = {}); - Selection(Selection&& other); - Selection(const Selection& other); - ~Selection(); - - Selection& operator=(const Selection& other); - Selection& operator=(Selection&& other); + CaptureList captures = {}) + : Range(first, last), m_captures(std::move(captures)) {} void avoid_eol(); CaptureList& captures() { return m_captures; } const CaptureList& captures() const { return m_captures; } + const Buffer& buffer() const { return first().buffer(); } private: - void on_insert(const BufferIterator& begin, - const BufferIterator& end) override; - void on_erase(const BufferIterator& begin, - const BufferIterator& end) override; - - void check_invariant() const; - - void register_with_buffer(); - void unregister_with_buffer(); CaptureList m_captures; }; @@ -75,4 +67,3 @@ using SelectionList = std::vector<Selection>; } #endif // selection_hh_INCLUDED - |
