Gather the list of hooks to run before running the parent
This will prevent hooks added by the parent hook manager to be gathered, as was decided during the discussion for #2603
This commit is contained in:
parent
a4f830f143
commit
1875ff51a0
|
@ -63,12 +63,26 @@ CandidateList HookManager::complete_hook_group(StringView prefix, ByteCount pos_
|
||||||
|
|
||||||
void HookManager::run_hook(Hook hook, StringView param, Context& context)
|
void HookManager::run_hook(Hook hook, StringView param, Context& context)
|
||||||
{
|
{
|
||||||
|
auto& hook_list = m_hooks[to_underlying(hook)];
|
||||||
|
|
||||||
const bool only_always = context.hooks_disabled();
|
const bool only_always = context.hooks_disabled();
|
||||||
|
auto& disabled_hooks = context.options()["disabled_hooks"].get<Regex>();
|
||||||
|
|
||||||
|
struct ToRun { HookData* hook; MatchResults<const char*> captures; };
|
||||||
|
Vector<ToRun> hooks_to_run; // The m_hooks_trash vector ensure hooks wont die during this method
|
||||||
|
for (auto& hook : hook_list)
|
||||||
|
{
|
||||||
|
MatchResults<const char*> captures;
|
||||||
|
if ((not only_always or (hook->flags & HookFlags::Always)) and
|
||||||
|
(hook->group.empty() or disabled_hooks.empty() or
|
||||||
|
not regex_match(hook->group.begin(), hook->group.end(), disabled_hooks))
|
||||||
|
and regex_match(param.begin(), param.end(), captures, hook->filter))
|
||||||
|
hooks_to_run.push_back({ hook.get(), std::move(captures) });
|
||||||
|
}
|
||||||
|
|
||||||
if (m_parent)
|
if (m_parent)
|
||||||
m_parent->run_hook(hook, param, context);
|
m_parent->run_hook(hook, param, context);
|
||||||
|
|
||||||
auto& hook_list = m_hooks[to_underlying(hook)];
|
|
||||||
auto hook_name = enum_desc(Meta::Type<Hook>{})[to_underlying(hook)].name;
|
auto hook_name = enum_desc(Meta::Type<Hook>{})[to_underlying(hook)].name;
|
||||||
if (contains(m_running_hooks, std::make_pair(hook, param)))
|
if (contains(m_running_hooks, std::make_pair(hook, param)))
|
||||||
{
|
{
|
||||||
|
@ -88,20 +102,6 @@ void HookManager::run_hook(Hook hook, StringView param, Context& context)
|
||||||
const bool profile = debug_flags & DebugFlags::Profile;
|
const bool profile = debug_flags & DebugFlags::Profile;
|
||||||
auto start_time = profile ? Clock::now() : TimePoint{};
|
auto start_time = profile ? Clock::now() : TimePoint{};
|
||||||
|
|
||||||
auto& disabled_hooks = context.options()["disabled_hooks"].get<Regex>();
|
|
||||||
|
|
||||||
struct ToRun { HookData* hook; MatchResults<const char*> captures; };
|
|
||||||
Vector<ToRun> hooks_to_run; // The m_hooks_trash vector ensure hooks wont die during this method
|
|
||||||
for (auto& hook : hook_list)
|
|
||||||
{
|
|
||||||
MatchResults<const char*> captures;
|
|
||||||
if ((not only_always or (hook->flags & HookFlags::Always)) and
|
|
||||||
(hook->group.empty() or disabled_hooks.empty() or
|
|
||||||
not regex_match(hook->group.begin(), hook->group.end(), disabled_hooks))
|
|
||||||
and regex_match(param.begin(), param.end(), captures, hook->filter))
|
|
||||||
hooks_to_run.push_back({ hook.get(), std::move(captures) });
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hook_error = false;
|
bool hook_error = false;
|
||||||
for (auto& to_run : hooks_to_run)
|
for (auto& to_run : hooks_to_run)
|
||||||
{
|
{
|
||||||
|
|
1
test/compose/do-not-run-hooks-added-by-parent/cmd
Normal file
1
test/compose/do-not-run-hooks-added-by-parent/cmd
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<ret><ret>
|
1
test/compose/do-not-run-hooks-added-by-parent/in
Normal file
1
test/compose/do-not-run-hooks-added-by-parent/in
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
test/compose/do-not-run-hooks-added-by-parent/out
Normal file
1
test/compose/do-not-run-hooks-added-by-parent/out
Normal file
|
@ -0,0 +1 @@
|
||||||
|
foo
|
5
test/compose/do-not-run-hooks-added-by-parent/rc
Normal file
5
test/compose/do-not-run-hooks-added-by-parent/rc
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
hook global NormalKey <ret> %{
|
||||||
|
hook window NormalKey <ret> %{
|
||||||
|
exec -draft ifoo<esc>
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user