From e4e609a35c6a5e45d495c5d2e0f99dd4c6dc33fb Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 8 May 2014 19:33:14 +0100 Subject: [PATCH] Catch std::runtime_errors that can be thrown by regex_search This handle the case where a regex matching gets too complex. --- src/normal.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/normal.cc b/src/normal.cc index c856ebe7..1b1f9152 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -603,6 +603,8 @@ void regex_prompt(Context& context, const String prompt, T func) [=](const String& str, PromptEvent event, Context& context) { try { + if (event != PromptEvent::Change and context.has_ui()) + context.ui().info_hide(); context.selections() = selections; context.input_handler().set_prompt_colors(get_color("Prompt")); if (event == PromptEvent::Abort) @@ -622,6 +624,22 @@ void regex_prompt(Context& context, const String prompt, T func) else context.input_handler().set_prompt_colors(get_color("Error")); } + catch (std::runtime_error& err) + { + if (event == PromptEvent::Validate) + throw runtime_error("regex error: "_str + err.what()); + else + { + context.input_handler().set_prompt_colors(get_color("Error")); + if (context.has_ui()) + { + ColorPair col = get_color("Information"); + CharCoord pos = context.window().dimensions(); + pos.column -= 1; + context.ui().info_show("regex error", err.what(), pos, col, MenuStyle::Prompt); + } + } + } catch (runtime_error&) { context.selections() = selections;