diff --git a/library/private/interactor_impl.h b/library/private/interactor_impl.h index ec901eba1b..304986e805 100644 --- a/library/private/interactor_impl.h +++ b/library/private/interactor_impl.h @@ -40,6 +40,8 @@ class interactor_impl : public interactor std::function&)> callback) override; interactor& removeCommand(const std::string& action) override; std::vector getCommandActions() const override; + std::unordered_map aliasMap; + void alias(const std::string& action, const std::string& value); bool triggerCommand(std::string_view command) override; interactor& initBindings() override; diff --git a/library/src/interactor_impl.cxx b/library/src/interactor_impl.cxx index 036574f6d5..6e112173f9 100644 --- a/library/src/interactor_impl.cxx +++ b/library/src/interactor_impl.cxx @@ -43,6 +43,11 @@ using mod_t = interaction_bind_t::ModifierKeys; class interactor_impl::internals { + //------------------------------------------------------------------- +private: + // Map to store aliases + std::map aliasMap; + //------------------------------------------------------------------- public: struct BindingCommands { @@ -753,6 +758,18 @@ std::vector interactor_impl::getCommandActions() const return actions; } +//---------------------------------------------------------------------------- +void interactor_impl::alias(const std::string& action, const std::string& value) +{ + if (action.empty() || value.empty()) + { + log::error("Alias action or value cannot be empty."); + return; + } + aliasMap[action] = value; + log::error("Alias added: " + action + " -> " + value); +} + //---------------------------------------------------------------------------- bool interactor_impl::triggerCommand(std::string_view command) { @@ -773,7 +790,16 @@ bool interactor_impl::triggerCommand(std::string_view command) return true; } - const std::string& action = tokens[0]; + std::string action = tokens[0]; + + // Check if action is an alias + auto aliasIt = aliasMap.find(action); + if (aliasIt != aliasMap.end()) + { + action = aliasIt->second; + log::error("Alias resolved: " + action); + } + try { // Find the right command to call