mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Keyboard widget: provide variable for shortcut descriptor to actions. (#5782)
This commit is contained in:
parent
3cd80de5bb
commit
8f9e8c1dee
@ -179,7 +179,7 @@ Key descriptors have the following format:
|
|||||||
ctrl+enter
|
ctrl+enter
|
||||||
ctrl+shift+alt+A
|
ctrl+shift+alt+A
|
||||||
*/
|
*/
|
||||||
KeyboardManager.prototype.parseKeyDescriptor = function(keyDescriptor) {
|
KeyboardManager.prototype.parseKeyDescriptor = function(keyDescriptor,options) {
|
||||||
var components = keyDescriptor.split(/\+|\-/),
|
var components = keyDescriptor.split(/\+|\-/),
|
||||||
info = {
|
info = {
|
||||||
keyCode: 0,
|
keyCode: 0,
|
||||||
@ -206,6 +206,9 @@ KeyboardManager.prototype.parseKeyDescriptor = function(keyDescriptor) {
|
|||||||
info.keyCode = this.namedKeys[s];
|
info.keyCode = this.namedKeys[s];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(options.keyDescriptor) {
|
||||||
|
info.keyDescriptor = options.keyDescriptor;
|
||||||
|
}
|
||||||
if(info.keyCode) {
|
if(info.keyCode) {
|
||||||
return info;
|
return info;
|
||||||
} else {
|
} else {
|
||||||
@ -237,6 +240,7 @@ KeyboardManager.prototype.parseKeyDescriptors = function(keyDescriptors,options)
|
|||||||
lookupName = function(configName) {
|
lookupName = function(configName) {
|
||||||
var keyDescriptors = wiki.getTiddlerText("$:/config/" + configName + "/" + name);
|
var keyDescriptors = wiki.getTiddlerText("$:/config/" + configName + "/" + name);
|
||||||
if(keyDescriptors) {
|
if(keyDescriptors) {
|
||||||
|
options.keyDescriptor = keyDescriptor;
|
||||||
result.push.apply(result,self.parseKeyDescriptors(keyDescriptors,options));
|
result.push.apply(result,self.parseKeyDescriptors(keyDescriptors,options));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -245,7 +249,7 @@ KeyboardManager.prototype.parseKeyDescriptors = function(keyDescriptors,options)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.push(self.parseKeyDescriptor(keyDescriptor));
|
result.push(self.parseKeyDescriptor(keyDescriptor,options));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
@ -276,12 +280,16 @@ KeyboardManager.prototype.checkKeyDescriptor = function(event,keyInfo) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
KeyboardManager.prototype.checkKeyDescriptors = function(event,keyInfoArray) {
|
KeyboardManager.prototype.checkKeyDescriptors = function(event,keyInfoArray) {
|
||||||
|
return (this.getMatchingKeyDescriptor(event,keyInfoArray) !== null);
|
||||||
|
};
|
||||||
|
|
||||||
|
KeyboardManager.prototype.getMatchingKeyDescriptor = function(event,keyInfoArray) {
|
||||||
for(var t=0; t<keyInfoArray.length; t++) {
|
for(var t=0; t<keyInfoArray.length; t++) {
|
||||||
if(this.checkKeyDescriptor(event,keyInfoArray[t])) {
|
if(this.checkKeyDescriptor(event,keyInfoArray[t])) {
|
||||||
return true;
|
return keyInfoArray[t];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
KeyboardManager.prototype.getEventModifierKeyDescriptor = function(event) {
|
KeyboardManager.prototype.getEventModifierKeyDescriptor = function(event) {
|
||||||
|
@ -53,7 +53,8 @@ KeyboardWidget.prototype.render = function(parent,nextSibling) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
KeyboardWidget.prototype.handleChangeEvent = function(event) {
|
KeyboardWidget.prototype.handleChangeEvent = function(event) {
|
||||||
if($tw.keyboardManager.checkKeyDescriptors(event,this.keyInfoArray)) {
|
var keyInfo = $tw.keyboardManager.getMatchingKeyDescriptor(event,this.keyInfoArray);
|
||||||
|
if(keyInfo) {
|
||||||
var handled = this.invokeActions(this,event);
|
var handled = this.invokeActions(this,event);
|
||||||
if(this.actions) {
|
if(this.actions) {
|
||||||
var variables = {
|
var variables = {
|
||||||
@ -61,6 +62,9 @@ KeyboardWidget.prototype.handleChangeEvent = function(event) {
|
|||||||
"event-code": event.code,
|
"event-code": event.code,
|
||||||
"modifier": $tw.keyboardManager.getEventModifierKeyDescriptor(event)
|
"modifier": $tw.keyboardManager.getEventModifierKeyDescriptor(event)
|
||||||
};
|
};
|
||||||
|
if(keyInfo.keyDescriptor) {
|
||||||
|
variables["event-key-descriptor"] = keyInfo.keyDescriptor;
|
||||||
|
}
|
||||||
this.invokeActionString(this.actions,this,event,variables);
|
this.invokeActionString(this.actions,this,event,variables);
|
||||||
}
|
}
|
||||||
this.dispatchMessage(event);
|
this.dispatchMessage(event);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
caption: keyboard
|
caption: keyboard
|
||||||
created: 20140302192136805
|
created: 20140302192136805
|
||||||
list: [[Keyboard Codes]] [[Key Codes (Example)]] [[Key Codes (Example 1)]] [[Possible Keys (Example 2)]]
|
list: [[Keyboard Codes]] [[Key Codes (Example)]] [[Key Codes (Example 1)]] [[Possible Keys (Example 2)]]
|
||||||
modified: 20210525102143381
|
modified: 20210612101618855
|
||||||
tags: Widgets
|
tags: Widgets
|
||||||
title: KeyboardWidget
|
title: KeyboardWidget
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
@ -30,6 +30,7 @@ The content of the `<$keyboard>` widget is rendered normally. The keyboard short
|
|||||||
|!Variables |!Description |
|
|!Variables |!Description |
|
||||||
|`event-key` |The <<.var event-key>> variable contains the character, if possible. eg: `1`. You can experiment with some settings at: [[Key Codes (Example)]] |
|
|`event-key` |The <<.var event-key>> variable contains the character, if possible. eg: `1`. You can experiment with some settings at: [[Key Codes (Example)]] |
|
||||||
|`event-code` |The <<.var event-code>> variable contains a character description. eg: `Digit1` instead of `1`. Or `Space` instead of an empty string ` `, which is hard to see|
|
|`event-code` |The <<.var event-code>> variable contains a character description. eg: `Digit1` instead of `1`. Or `Space` instead of an empty string ` `, which is hard to see|
|
||||||
|
|`event-key-descriptor` |The <<.var event-key-descriptor>> variable is available if the keyboard event captured was configured using a [[keyboard shortcut descriptor|Keyboard Shortcut Descriptor]] of the form `((my-shortcut))` which references a configuration tiddler. |
|
||||||
|`modifier` |The [[modifier Variable]] contains the Modifier Key held during the event (can be <kbd>normal</kbd>, <kbd>ctrl</kbd>, <kbd>shift</kbd>, <kbd>alt</kbd> or combinations thereof) |
|
|`modifier` |The [[modifier Variable]] contains the Modifier Key held during the event (can be <kbd>normal</kbd>, <kbd>ctrl</kbd>, <kbd>shift</kbd>, <kbd>alt</kbd> or combinations thereof) |
|
||||||
|
|
||||||
! Key Strings
|
! Key Strings
|
||||||
|
Loading…
Reference in New Issue
Block a user