From dc378aed7290eb9fd90b752a2841fa2457bb91d0 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 26 Jun 2017 14:56:50 +0100 Subject: Pass a context instead of just the buffer to selector functions --- src/normal.cc | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/normal.cc') diff --git a/src/normal.cc b/src/normal.cc index 16f1a4c2..033eef34 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -35,12 +35,11 @@ enum class SelectMode template void select(Context& context, T func) { - auto& buffer = context.buffer(); auto& selections = context.selections(); if (mode == SelectMode::Append) { auto& sel = selections.main(); - if (auto res = func(buffer, sel)) + if (auto res = func(context, sel)) { if (res->captures().empty()) res->captures() = sel.captures(); @@ -54,7 +53,7 @@ void select(Context& context, T func) for (int i = 0; i < (int)selections.size(); ++i) { auto& sel = selections[i]; - auto res = func(buffer, sel); + auto res = func(context, sel); if (not res) { to_remove.push_back(i); @@ -82,7 +81,7 @@ void select(Context& context, T func) selections.check_invariant(); } -template (*func)(const Buffer&, const Selection&)> +template (*func)(const Context&, const Selection&)> void select(Context& context, NormalParams) { select(context, func); @@ -727,15 +726,14 @@ void search(Context& context, NormalParams params) { int c = count; auto& selections = context.selections(); - auto& buffer = context.buffer(); do { bool wrapped = false; for (auto& sel : selections) { if (mode == SelectMode::Replace) - sel = keep_direction(find_next_match(buffer, sel, regex, wrapped), sel); + sel = keep_direction(find_next_match(context, sel, regex, wrapped), sel); if (mode == SelectMode::Extend) - sel.merge_with(find_next_match(buffer, sel, regex, wrapped)); + sel.merge_with(find_next_match(context, sel, regex, wrapped)); } selections.sort_and_merge_overlapping(); } while (--c > 0); @@ -752,19 +750,18 @@ void search_next(Context& context, NormalParams params) { Regex regex{str}; auto& selections = context.selections(); - auto& buffer = context.buffer(); bool main_wrapped = false; do { bool wrapped = false; if (mode == SelectMode::Replace) { auto& sel = selections.main(); - sel = keep_direction(find_next_match(buffer, sel, regex, wrapped), sel); + sel = keep_direction(find_next_match(context, sel, regex, wrapped), sel); } else if (mode == SelectMode::Append) { auto sel = keep_direction( - find_next_match(buffer, selections.main(), regex, wrapped), + find_next_match(context, selections.main(), regex, wrapped), selections.main()); selections.push_back(std::move(sel)); selections.set_main_index(selections.size() - 1); @@ -1077,7 +1074,7 @@ void select_object(Context& context, NormalParams params) static constexpr struct ObjectType { Codepoint key; - Optional (*func)(const Buffer&, const Selection&, int, ObjectFlags); + Optional (*func)(const Context&, const Selection&, int, ObjectFlags); } selectors[] = { { 'w', select_word }, { 'W', select_word }, -- cgit v1.2.3