From eb81eef03ee794b82e23026c01cd2fc4a1a78076 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 15 Dec 2013 14:38:04 +0000 Subject: Move SelectMode enum as an implementation detail in normal.cc --- src/normal.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/normal.cc') diff --git a/src/normal.cc b/src/normal.cc index ec8f32c0..aab5a029 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -22,6 +22,14 @@ namespace Kakoune using namespace std::placeholders; +enum class SelectMode +{ + Replace, + Extend, + Append, + ReplaceMain, +}; + template class Select { @@ -360,6 +368,30 @@ void pipe(Context& context, int) }); } +template +void select_next_match(const Buffer& buffer, SelectionList& selections, + const Regex& regex) +{ + if (mode == SelectMode::Replace) + { + for (auto& sel : selections) + sel = find_next_match(buffer, sel, regex); + } + if (mode == SelectMode::Extend) + { + for (auto& sel : selections) + sel.merge_with(find_next_match(buffer, sel, regex)); + } + else if (mode == SelectMode::ReplaceMain) + selections.main() = find_next_match(buffer, selections.main(), regex); + else if (mode == SelectMode::Append) + { + selections.push_back(find_next_match(buffer, selections.main(), regex)); + selections.set_main_index(selections.size() - 1); + } + selections.sort_and_merge_overlapping(); +} + template void search(Context& context, int) { -- cgit v1.2.3