From 6cc4ec796edfb62e693f4b582fdd90db5f2557a8 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 18 Dec 2012 19:12:15 +0100 Subject: [PATCH] editor: support select mode on select(BufferIterator) --- src/editor.cc | 13 +++++++++++-- src/editor.hh | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/editor.cc b/src/editor.cc index 02baf5f5..9ed99a93 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -200,9 +200,18 @@ void Editor::remove_selection(int index) m_selections.erase(m_selections.begin() + index); } -void Editor::select(const BufferIterator& iterator) +void Editor::select(const BufferIterator& iterator, SelectMode mode) { - m_selections = SelectionList{ {iterator, iterator} }; + if (mode == SelectMode::Replace) + m_selections = SelectionList{ {iterator, iterator} }; + else if (mode == SelectMode::Extend) + { + for (auto& sel : m_selections) + sel.last() = iterator; + merge_overlapping(m_selections); + } + else if (mode == SelectMode::Append) + assert(false); } void Editor::select(SelectionList selections) diff --git a/src/editor.hh b/src/editor.hh index c1ea19d5..3ca639c2 100644 --- a/src/editor.hh +++ b/src/editor.hh @@ -62,7 +62,8 @@ public: void flip_selections(); void keep_selection(int index); void remove_selection(int index); - void select(const BufferIterator& iterator); + void select(const BufferIterator& iterator, + SelectMode mode = SelectMode::Replace); void select(const Selector& selector, SelectMode mode = SelectMode::Replace); void select(SelectionList selections);