diff --git a/core/modules/macros/edit/edit.js b/core/modules/macros/edit/edit.js index 219458e95..feb15924e 100644 --- a/core/modules/macros/edit/edit.js +++ b/core/modules/macros/edit/edit.js @@ -15,10 +15,11 @@ Edit macro for editting fields and tiddlers exports.info = { name: "edit", params: { - field: {byPos: 0, type: "text"}, tiddler: {byName: true, type: "tiddler"}, + field: {byPos: 0, type: "text"}, type: {byName: true, type: "text"}, - "default": {byName: true, type: "text"} + "default": {byName: true, type: "text"}, + requireFocus: {byName: true, type: "text"} } }; diff --git a/core/modules/macros/edit/editors/texteditor.js b/core/modules/macros/edit/editors/texteditor.js index bb0138311..3f942d608 100644 --- a/core/modules/macros/edit/editors/texteditor.js +++ b/core/modules/macros/edit/editors/texteditor.js @@ -81,28 +81,34 @@ TextEditor.prototype.getChild = function() { break; } // Wrap the editor control in a div - return $tw.Tree.Element(this.macroNode.isBlock ? "div" : "span",{},[$tw.Tree.Element(tagName,attributes,content)],{ - events: ["focus","keyup"], + return $tw.Tree.Element(this.macroNode.isBlock ? "div" : "span",{},[$tw.Tree.Element(tagName,attributes,content,{ + events: ["focus","blur","keyup"], eventHandler: this - }); + })]); }; TextEditor.prototype.handleEvent = function(event) { +console.log("event type",event.type); // Get the value of the field if it might have changed - if("keyup".split(" ").indexOf(event.type) !== -1) { + if("keyup focus blur".split(" ").indexOf(event.type) !== -1) { this.saveChanges(); } - // Whatever the event, fix the height of the textarea if required - var self = this; - window.setTimeout(function() { - self.fixHeight(); - },5); + // Fix the height of the textarea if required + if("keyup focus".split(" ").indexOf(event.type) !== -1) { + var self = this; + window.setTimeout(function() { + self.fixHeight(); + },5); + } return true; }; TextEditor.prototype.saveChanges = function() { var text = this.macroNode.child.children[0].domNode.value, tiddler = this.macroNode.wiki.getTiddler(this.macroNode.editTiddler); + if(this.macroNode.params.requireFocus === "yes" && document.activeElement !== this.macroNode.child.children[0].domNode) { + text = this.macroNode.params["default"] || ""; + } if(!tiddler) { tiddler = new $tw.Tiddler({title: this.macroNode.editTiddler}); } diff --git a/core/templates/PageTemplate.tid b/core/templates/PageTemplate.tid index cf1acd492..01444940c 100644 --- a/core/templates/PageTemplate.tid +++ b/core/templates/PageTemplate.tid @@ -24,10 +24,11 @@ title: $:/templates/PageTemplate * [[Docs]] *{{divider-vertical}} +