From 18902b15afafc585bde7bc333e690583c7ef0e2f Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 4 Oct 2023 21:03:10 +1100 Subject: [PATCH] Refactor regex_prompt logic and fix function being called on abort Fixes #4993 --- src/normal.cc | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index 81caeb2d..c93c4760 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -854,20 +854,22 @@ void regex_prompt(Context& context, String prompt, char reg, T func) context.input_handler().set_prompt_face(context.faces()["Prompt"]); } - - if (not incsearch and event == PromptEvent::Change) - return; - - if (event == PromptEvent::Validate) - context.push_jump(); - else - RegisterManager::instance()[reg].restore(context, saved_reg); - - if (not str.empty() and event == PromptEvent::Change) // Ensure search register based highlighters work incrementally - RegisterManager::instance()[reg].set(context, str.str()); - - if (not str.empty() or event == PromptEvent::Validate) - func(Regex{str.empty() ? default_regex : str, direction_flags(mode)}, event, context); + switch (event) + { + case PromptEvent::Change: + if (not incsearch or str.empty()) + return; + RegisterManager::instance()[reg].set(context, str.str()); + func(Regex{str, direction_flags(mode)}, event, context); + return; + case PromptEvent::Abort: + RegisterManager::instance()[reg].restore(context, saved_reg); + return; + case PromptEvent::Validate: + context.push_jump(); + func(Regex{str.empty() ? default_regex : str, direction_flags(mode)}, event, context); + return; + } } catch (regex_error& err) {