diff --git a/core/modules/keyboard.js b/core/modules/keyboard.js index bfa76d7e2..a63d48fbe 100644 --- a/core/modules/keyboard.js +++ b/core/modules/keyboard.js @@ -138,6 +138,17 @@ function KeyboardManager(options) { }); // Save the platform-specific name of the "meta" key this.metaKeyName = $tw.platform.isMac ? "cmd-" : "win-"; + this.shortcutKeysList = [], // Stores the shortcut-key descriptors + this.shortcutActionList = [], // Stores the corresponding action strings + this.shortcutParsedList = []; // Stores the parsed key descriptors + this.lookupNames = ["shortcuts"]; + this.lookupNames.push($tw.platform.isMac ? "shortcuts-mac" : "shortcuts-not-mac") + this.lookupNames.push($tw.platform.isWindows ? "shortcuts-windows" : "shortcuts-not-windows"); + this.lookupNames.push($tw.platform.isLinux ? "shortcuts-linux" : "shortcuts-not-linux"); + this.updateShortcutLists(this.getShortcutTiddlerList()); + $tw.wiki.addEventListener("change",function(changes) { + self.handleShortcutChanges(changes); + }); } /* @@ -229,10 +240,9 @@ KeyboardManager.prototype.parseKeyDescriptors = function(keyDescriptors,options) result.push.apply(result,self.parseKeyDescriptors(keyDescriptors,options)); } }; - lookupName("shortcuts"); - lookupName($tw.platform.isMac ? "shortcuts-mac" : "shortcuts-not-mac"); - lookupName($tw.platform.isWindows ? "shortcuts-windows" : "shortcuts-not-windows"); - lookupName($tw.platform.isLinux ? "shortcuts-linux" : "shortcuts-not-linux"); + $tw.utils.each(self.lookupNames,function(platformDescriptor) { + lookupName(platformDescriptor); + }); } } else { result.push(self.parseKeyDescriptor(keyDescriptor)); @@ -274,6 +284,70 @@ KeyboardManager.prototype.checkKeyDescriptors = function(event,keyInfoArray) { return false; }; +KeyboardManager.prototype.getShortcutTiddlerList = function() { + return $tw.wiki.getTiddlersWithTag("$:/tags/KeyboardShortcut"); +}; + +KeyboardManager.prototype.updateShortcutLists = function(tiddlerList) { + this.shortcutTiddlers = tiddlerList; + for(var i=0; i