1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-23 23:34:12 +03:00

Catch std::runtime_errors that can be thrown by regex_search

This handle the case where a regex matching gets too complex.
This commit is contained in:
Maxime Coste 2014-05-08 19:33:14 +01:00
parent 4010117c98
commit e4e609a35c

View File

@ -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;