fix(renderer): Handle nested actions events properly

For nested actions, the inner action should override the outer action.
But because the list of actions was not iterated in reverse the outer
action was matched first.

Fixes #760
This commit is contained in:
patrick96 2017-09-23 16:50:57 +02:00
parent 251c3e874a
commit c7cb5ebf94
No known key found for this signature in database
GPG Key ID: 521E5E03AEBCA1A7

View File

@ -689,13 +689,20 @@ void bar::handle(const evt::button_press& evt) {
m_buttonpress_pos = evt->event_x;
const auto deferred_fn = [&](size_t) {
for (auto&& action : m_renderer->actions()) {
if (action.button == m_buttonpress_btn && !action.active && action.test(m_buttonpress_pos)) {
/*
* Iterate over all defined actions in reverse order until matching action is found
* To properly handle nested actions we iterate in reverse because nested actions are added later than their
* surrounding action block
*/
auto actions = m_renderer->actions();
for (auto action = actions.rbegin(); action != actions.rend(); action++) {
if (action->button == m_buttonpress_btn && !action->active && action->test(m_buttonpress_pos)) {
m_log.trace("Found matching input area");
m_sig.emit(button_press{string{action.command}});
m_sig.emit(button_press{string{action->command}});
return;
}
}
for (auto&& action : m_opts.actions) {
if (action.button == m_buttonpress_btn && !action.command.empty()) {
m_log.trace("Found matching fallback handler");