From 00ff0d6fa0f54c9b2dc8e47c22d58d9f80113664 Mon Sep 17 00:00:00 2001 From: Simon Huber Date: Tue, 14 Jul 2020 18:04:06 +0200 Subject: [PATCH] Add modifier variable to button actionstring (#4671) * Add modifier variable to button actionstring * Update ButtonWidget.tid * Update droppable.js * Create getEventModifierKeyDescriptor method in keyboard.js * Update droppable.js * Update button.js --- core/modules/keyboard.js | 10 ++++++++++ core/modules/widgets/button.js | 3 ++- core/modules/widgets/droppable.js | 3 +-- editions/tw5.com/tiddlers/widgets/ButtonWidget.tid | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/modules/keyboard.js b/core/modules/keyboard.js index a63d48fbe..a58e1685d 100644 --- a/core/modules/keyboard.js +++ b/core/modules/keyboard.js @@ -284,6 +284,16 @@ KeyboardManager.prototype.checkKeyDescriptors = function(event,keyInfoArray) { return false; }; +KeyboardManager.prototype.getEventModifierKeyDescriptor = function(event) { + return event.ctrlKey && !event.shiftKey && !event.altKey ? "ctrl" : + event.shiftKey && !event.ctrlKey && !event.altKey? "shift" : + event.ctrlKey && event.shiftKey && !event.altKey ? "ctrl-shift" : + event.altKey && !event.shiftKey && !event.ctrlKey ? "alt" : + event.altKey && event.shiftKey && !event.ctrlKey ? "alt-shift" : + event.altKey && event.ctrlKey && !event.shiftKey ? "ctrl-alt" : + event.altKey && event.shiftKey && event.ctrlKey ? "ctrl-alt-shift" : "normal"; +}; + KeyboardManager.prototype.getShortcutTiddlerList = function() { return $tw.wiki.getTiddlersWithTag("$:/tags/KeyboardShortcut"); }; diff --git a/core/modules/widgets/button.js b/core/modules/widgets/button.js index 67eaf26b9..204a7edf4 100644 --- a/core/modules/widgets/button.js +++ b/core/modules/widgets/button.js @@ -91,7 +91,8 @@ ButtonWidget.prototype.render = function(parent,nextSibling) { handled = true; } if(self.actions) { - self.invokeActionString(self.actions,self,event); + var modifierKey = $tw.keyboardManager.getEventModifierKeyDescriptor(event); + self.invokeActionString(self.actions,self,event,{modifier: modifierKey}); } if(handled) { event.preventDefault(); diff --git a/core/modules/widgets/droppable.js b/core/modules/widgets/droppable.js index 45f11bf68..e6678527b 100644 --- a/core/modules/widgets/droppable.js +++ b/core/modules/widgets/droppable.js @@ -132,8 +132,7 @@ DroppableWidget.prototype.handleDropEvent = function(event) { DroppableWidget.prototype.performActions = function(title,event) { if(this.droppableActions) { - var modifierKey = event.ctrlKey && ! event.shiftKey ? "ctrl" : event.shiftKey && !event.ctrlKey ? "shift" : - event.ctrlKey && event.shiftKey ? "ctrl-shift" : "normal" ; + var modifierKey = $tw.keyboardManager.getEventModifierKeyDescriptor(event); this.invokeActionString(this.droppableActions,this,event,{actionTiddler: title, modifier: modifierKey}); } }; diff --git a/editions/tw5.com/tiddlers/widgets/ButtonWidget.tid b/editions/tw5.com/tiddlers/widgets/ButtonWidget.tid index 21a0a48a1..fcaf50f1d 100644 --- a/editions/tw5.com/tiddlers/widgets/ButtonWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/ButtonWidget.tid @@ -24,7 +24,7 @@ The integrated actions are provided as a shortcut for invoking common actions. T The content of the `<$button>` widget is displayed within the button. |!Attribute |!Description | -|actions |A string containing ActionWidgets to be triggered when the key combination is detected | +|actions |A string containing ActionWidgets to be triggered when the key combination is detected. <<.from-version "5.1.23">> the <<.def "modifier">> variable lists the modifier keys that are pressed when the action is invoked. The possible modifiers are ''ctrl'', ''ctrl-alt'', ''ctrl-shift'', ''alt'', ''alt-shift'', ''shift'' and ''ctrl-alt-shift'' | |to |The title of the tiddler to navigate to | |message |The name of the [[widget message|Messages]] to send when the button is clicked | |param |The optional parameter to the message |