| 617 | } |
| 618 | |
| 619 | Action InputBindings::getActionForKey(ToolMode mode, int key, int modifiers) const { |
| 620 | const int mods = modifiers & MODIFIER_MASK; |
| 621 | const auto find_in_mode = [&](ToolMode query_mode) -> Action { |
| 622 | if (auto it = key_map_.find({query_mode, key, mods}); it != key_map_.end()) { |
| 623 | return it->second; |
| 624 | } |
| 625 | if (mods != MODIFIER_NONE) { |
| 626 | if (auto it = key_map_.find({query_mode, key, MODIFIER_NONE}); |
| 627 | it != key_map_.end() && |
| 628 | describe(it->second).allows_extra_modifiers) { |
| 629 | return it->second; |
| 630 | } |
| 631 | } |
| 632 | return Action::NONE; |
| 633 | }; |
| 634 | |
| 635 | if (const auto local_action = find_in_mode(mode); local_action != Action::NONE) { |
| 636 | return local_action; |
| 637 | } |
| 638 | |
| 639 | if (mode != ToolMode::GLOBAL) { |
| 640 | const auto global_action = find_in_mode(ToolMode::GLOBAL); |
| 641 | if (global_action != Action::NONE && |
| 642 | describe(global_action).inherits_from_global) { |
| 643 | return global_action; |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | // Support the common redo alias when the profile still uses the default Ctrl+Y binding. |
| 648 | const auto redo_trigger = [&]() -> std::optional<InputTrigger> { |
| 649 | if (auto trigger = getTriggerForAction(Action::REDO, mode)) { |
| 650 | return trigger; |
| 651 | } |
| 652 | if (mode != ToolMode::GLOBAL) { |
| 653 | return getTriggerForAction(Action::REDO, ToolMode::GLOBAL); |
| 654 | } |
| 655 | return std::nullopt; |
| 656 | }(); |
| 657 | if (key == KEY_Z && |
| 658 | mods == (MODIFIER_CTRL | MODIFIER_SHIFT) && |
| 659 | triggerUsesDefaultRedoBinding(redo_trigger)) { |
| 660 | return Action::REDO; |
| 661 | } |
| 662 | |
| 663 | return Action::NONE; |
| 664 | } |
| 665 | |
| 666 | Action InputBindings::getActionForMouseButton(ToolMode mode, MouseButton button, int modifiers, bool is_double_click) const { |
| 667 | const int mods = modifiers & MODIFIER_MASK; |