1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Keyboard widget: don't refresh when class changes (#5758)

This commit is contained in:
Simon Huber 2021-06-06 12:03:08 +02:00 committed by GitHub
parent afa4ea3d03
commit 2f1806ab6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,9 +40,8 @@ KeyboardWidget.prototype.render = function(parent,nextSibling) {
// Create element
var domNode = this.document.createElement(tag);
// Assign classes
var classes = (this["class"] || "").split(" ");
classes.push("tc-keyboard");
domNode.className = classes.join(" ");
this.domNode = domNode;
this.assignDomNodeClasses();
// Add a keyboard event handler
$tw.utils.addEventListeners(domNode,[
{name: "keydown", handlerObject: this, handlerMethod: "handleChangeEvent"}
@ -90,7 +89,6 @@ KeyboardWidget.prototype.execute = function() {
this.key = this.getAttribute("key","");
this.tag = this.getAttribute("tag","");
this.keyInfoArray = $tw.keyboardManager.parseKeyDescriptors(this.key);
this["class"] = this.getAttribute("class","");
if(this.key.substr(0,2) === "((" && this.key.substr(-2,2) === "))") {
this.shortcutTiddlers = [];
var name = this.key.substring(2,this.key.length -2);
@ -102,14 +100,22 @@ KeyboardWidget.prototype.execute = function() {
this.makeChildWidgets();
};
KeyboardWidget.prototype.assignDomNodeClasses = function() {
var classes = this.getAttribute("class","").split(" ");
classes.push("tc-keyboard");
this.domNode.className = classes.join(" ");
};
/*
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
*/
KeyboardWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes.message || changedAttributes.param || changedAttributes.key || changedAttributes["class"] || changedAttributes.tag) {
if(changedAttributes.message || changedAttributes.param || changedAttributes.key || changedAttributes.tag) {
this.refreshSelf();
return true;
} else if(changedAttributes["class"]) {
this.assignDomNodeClasses();
}
// Update the keyInfoArray if one of its shortcut-config-tiddlers has changed
if(this.shortcutTiddlers && $tw.utils.hopArray(changedTiddlers,this.shortcutTiddlers)) {