From eb81eef03ee794b82e23026c01cd2fc4a1a78076 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 15 Dec 2013 14:38:04 +0000 Subject: [PATCH] Move SelectMode enum as an implementation detail in normal.cc --- src/editor.hh | 8 -------- src/normal.cc | 32 ++++++++++++++++++++++++++++++++ src/selectors.hh | 24 ------------------------ 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/editor.hh b/src/editor.hh index b26a8fee..5a468279 100644 --- a/src/editor.hh +++ b/src/editor.hh @@ -12,14 +12,6 @@ namespace InputModes { class Insert; } class Register; -enum class SelectMode -{ - Replace, - Extend, - Append, - ReplaceMain, -}; - enum class InsertMode : unsigned { Insert, 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) { diff --git a/src/selectors.hh b/src/selectors.hh index 84cc9ed9..da9b195f 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -266,30 +266,6 @@ Selection find_next_match(const Buffer& buffer, const Selection& sel, const Rege return {begin.coord(), end.coord(), std::move(captures)}; } -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(); -} - void select_all_matches(const Buffer& buffer, SelectionList& selections, const Regex& regex);