summaryrefslogtreecommitdiff
path: root/src/dynamic_selection_list.hh
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2012-12-11 19:51:59 +0100
committerMaxime Coste <frrrwww@gmail.com>2012-12-13 18:50:27 +0100
commitcfd7ee049a7c668bb2269029d159b34d2014ece6 (patch)
treedc8d3eef1af8318acde758de012db858d4c36e30 /src/dynamic_selection_list.hh
parente36bc74f431e2f98f049724536da86af9051811d (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/dynamic_selection_list.hh')
-rw-r--r--src/dynamic_selection_list.hh67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/dynamic_selection_list.hh b/src/dynamic_selection_list.hh
new file mode 100644
index 00000000..5e76f662
--- /dev/null
+++ b/src/dynamic_selection_list.hh
@@ -0,0 +1,67 @@
+#ifndef dynamic_selection_list_hh_INCLUDED
+#define dynamic_selection_list_hh_INCLUDED
+
+#include "selection.hh"
+
+namespace Kakoune
+{
+
+class DynamicSelectionList : public BufferChangeListener
+{
+public:
+ using iterator = SelectionList::iterator;
+ using const_iterator = SelectionList::const_iterator;
+
+ DynamicSelectionList(const Buffer& buffer, SelectionList selections = {});
+ ~DynamicSelectionList();
+
+ DynamicSelectionList(const DynamicSelectionList& other);
+ DynamicSelectionList& operator=(const DynamicSelectionList& other);
+ DynamicSelectionList(DynamicSelectionList&& other);
+ DynamicSelectionList& operator=(DynamicSelectionList&& other);
+
+ size_t size() const { return m_selections.size(); }
+ bool empty() const { return m_selections.empty(); }
+
+ void clear() { m_selections.clear(); }
+ iterator erase(iterator it) { return m_selections.erase(it); }
+
+ void push_back(Selection selection)
+ {
+ assert(&selection.buffer() == m_buffer);
+ m_selections.push_back(std::move(selection));
+ }
+
+ void reset(SelectionList selections);
+
+ iterator begin() { return m_selections.begin(); }
+ iterator end() { return m_selections.end(); }
+ const_iterator begin() const { return m_selections.begin(); }
+ const_iterator end() const { return m_selections.end(); }
+
+ Selection& front() { return m_selections.front(); }
+ Selection& back() { return m_selections.back(); }
+ const Selection& front() const { return m_selections.front(); }
+ const Selection& back() const { return m_selections.back(); }
+
+ Selection& operator[](size_t index) { return m_selections[index]; }
+ const Selection& operator[](size_t index) const { return m_selections[index]; }
+
+ operator const SelectionList&() const { return m_selections; }
+
+ const Buffer& buffer() const { return *m_buffer; }
+
+private:
+ void on_insert(const BufferIterator& begin,
+ const BufferIterator& end) override;
+ void on_erase(const BufferIterator& begin,
+ const BufferIterator& end) override;
+
+ const Buffer* m_buffer;
+ SelectionList m_selections;
+};
+
+};
+
+#endif // dynamic_selection_list_hh_INCLUDED
+