From 7dfdbae812306875bac2445ca4ee505b406e3be1 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 29 Aug 2024 17:25:30 +0100 Subject: [PATCH] Keyboard widget should not crash if the keyboard manager has not been initialised A user reported a problem with using the keyboard widget within a startup action. --- core/modules/widgets/keyboard.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/modules/widgets/keyboard.js b/core/modules/widgets/keyboard.js index ce3162f51..9515f5a3b 100644 --- a/core/modules/widgets/keyboard.js +++ b/core/modules/widgets/keyboard.js @@ -96,13 +96,15 @@ KeyboardWidget.prototype.execute = function() { this.param = this.getAttribute("param",""); this.key = this.getAttribute("key",""); this.tag = this.getAttribute("tag",""); - this.keyInfoArray = $tw.keyboardManager.parseKeyDescriptors(this.key); - if(this.key.substr(0,2) === "((" && this.key.substr(-2,2) === "))") { - this.shortcutTiddlers = []; - var name = this.key.substring(2,this.key.length -2); - $tw.utils.each($tw.keyboardManager.lookupNames,function(platformDescriptor) { - self.shortcutTiddlers.push("$:/config/" + platformDescriptor + "/" + name); - }); + if($tw.keyboardManager) { + this.keyInfoArray = $tw.keyboardManager.parseKeyDescriptors(this.key); + if(this.key.substr(0,2) === "((" && this.key.substr(-2,2) === "))") { + this.shortcutTiddlers = []; + var name = this.key.substring(2,this.key.length -2); + $tw.utils.each($tw.keyboardManager.lookupNames,function(platformDescriptor) { + self.shortcutTiddlers.push("$:/config/" + platformDescriptor + "/" + name); + }); + } } // Make child widgets this.makeChildWidgets(); @@ -126,7 +128,7 @@ KeyboardWidget.prototype.refresh = function(changedTiddlers) { this.assignDomNodeClasses(); } // Update the keyInfoArray if one of its shortcut-config-tiddlers has changed - if(this.shortcutTiddlers && $tw.utils.hopArray(changedTiddlers,this.shortcutTiddlers)) { + if(this.shortcutTiddlers && $tw.utils.hopArray(changedTiddlers,this.shortcutTiddlers) && $tw.keyboardManager) { this.keyInfoArray = $tw.keyboardManager.parseKeyDescriptors(this.key); } return this.refreshChildren(changedTiddlers);