Refactor regex_prompt logic and fix function being called on abort

Fixes #4993
This commit is contained in:
Maxime Coste 2023-10-04 21:03:10 +11:00
parent 7be996e5a4
commit 18902b15af

View File

@ -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)
switch (event)
{
case PromptEvent::Change:
if (not incsearch or str.empty())
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, 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)
{