From 36793b5164dc685ad5ece838aa193bf2c50086c8 Mon Sep 17 00:00:00 2001 From: molsonkiko <46202915+molsonkiko@users.noreply.github.com> Date: Wed, 14 Feb 2024 15:26:20 -0800 Subject: [PATCH 1/2] Enable shortcut mapper to filter keycombos for scintilla commands Previously the shortcut mapper filtered the keycombo for every other type of command, but not scintilla commands. --- .../src/WinControls/Grid/ShortcutMapper.cpp | 35 +++++++++++++++++++ .../src/WinControls/Grid/ShortcutMapper.h | 1 + 2 files changed, 36 insertions(+) diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp index da7f0a95d..c0cacff55 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp @@ -222,6 +222,41 @@ bool ShortcutMapper::isFilterValid(PluginCmdShortcut sc) return match; } +bool ShortcutMapper::isFilterValid(ScintillaKeyMap sc) +{ + // do a classic search on shortcut name, then see if *any* keycombo in _keyCombos matches + if (_shortcutFilter.empty()) + return true; + + wstring shortcut_name = stringToLower(string2wstring(sc.getName(), CP_UTF8)); + if (shortcut_name.find(_shortcutFilter) != std::string::npos) + return true; // name matches; don't have to check shortcuts + + for (size_t i = 0; i < sc.getSize(); ++i) + { + KeyCombo keyCombo = sc.getKeyComboByIndex(i); + if (keyCombo._key != 0) + { + // check if this stringified shortcut matches + string sc; + if (keyCombo._isCtrl) + sc += "Ctrl+"; + if (keyCombo._isAlt) + sc += "Alt+"; + if (keyCombo._isShift) + sc += "Shift+"; + + string keyString; + getKeyStrFromVal(keyCombo._key, keyString); + sc += keyString; + wstring combo_value = stringToLower(string2wstring(sc, CP_UTF8)); + if (combo_value.find(_shortcutFilter) != std::string::npos) + return true; + } + } + return false; +} + void ShortcutMapper::fillOutBabyGrid() { NppParameters& nppParam = NppParameters::getInstance(); diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.h b/PowerEditor/src/WinControls/Grid/ShortcutMapper.h index a96f02907..cad79cf91 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.h +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.h @@ -57,6 +57,7 @@ public: generic_string getTextFromCombo(HWND hCombo); bool isFilterValid(Shortcut); bool isFilterValid(PluginCmdShortcut sc); + bool isFilterValid(ScintillaKeyMap sc); protected : intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); From 840c4e58545532e80c68ba1872f0dff1c01c9df0 Mon Sep 17 00:00:00 2001 From: molsonkiko <46202915+molsonkiko@users.noreply.github.com> Date: Thu, 15 Feb 2024 14:31:40 -0800 Subject: [PATCH 2/2] use ScintillaKeyMap::toString() to get all shortcuts simplifies code, also matches "or" in a list of multiple shortcuts. --- .../src/WinControls/Grid/ShortcutMapper.cpp | 30 ++++--------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp index c0cacff55..3ae70a405 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp @@ -224,37 +224,17 @@ bool ShortcutMapper::isFilterValid(PluginCmdShortcut sc) bool ShortcutMapper::isFilterValid(ScintillaKeyMap sc) { - // do a classic search on shortcut name, then see if *any* keycombo in _keyCombos matches + // do a classic search on shortcut name, + // then see if the list of keycombos matches (e.g. "Ctrl+X or Alt+Y" matches "or" and "Alt" and "Ctrl+") if (_shortcutFilter.empty()) return true; wstring shortcut_name = stringToLower(string2wstring(sc.getName(), CP_UTF8)); if (shortcut_name.find(_shortcutFilter) != std::string::npos) - return true; // name matches; don't have to check shortcuts + return true; // name matches - for (size_t i = 0; i < sc.getSize(); ++i) - { - KeyCombo keyCombo = sc.getKeyComboByIndex(i); - if (keyCombo._key != 0) - { - // check if this stringified shortcut matches - string sc; - if (keyCombo._isCtrl) - sc += "Ctrl+"; - if (keyCombo._isAlt) - sc += "Alt+"; - if (keyCombo._isShift) - sc += "Shift+"; - - string keyString; - getKeyStrFromVal(keyCombo._key, keyString); - sc += keyString; - wstring combo_value = stringToLower(string2wstring(sc, CP_UTF8)); - if (combo_value.find(_shortcutFilter) != std::string::npos) - return true; - } - } - return false; + wstring shortcut_value = stringToLower(string2wstring(sc.toString(), CP_UTF8)); + return shortcut_value.find(_shortcutFilter) != std::string::npos; // list of shortcuts matches } void ShortcutMapper::fillOutBabyGrid()