mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-03-24 04:16:56 +00:00
Refactored editor logic to handle refreshes more efficiently
This commit is contained in:
parent
6a0a4ae00d
commit
d16481c524
@ -50,16 +50,8 @@ exports.refreshInDom = function(changes) {
|
||||
var t;
|
||||
// Only refresh if a dependency is triggered
|
||||
if(this.dependencies.hasChanged(changes,this.tiddlerTitle)) {
|
||||
// Only refresh if the editor lets us
|
||||
if(this.editor.isRefreshable()) {
|
||||
// Remove the previous child
|
||||
var parent = this.child.domNode.parentNode,
|
||||
nextSibling = this.child.domNode.nextSibling;
|
||||
parent.removeChild(this.child.domNode);
|
||||
// Execute the macro
|
||||
this.execute(this.parents,this.tiddlerTitle);
|
||||
// Render to the DOM
|
||||
this.child.renderInDom(parent,nextSibling);
|
||||
if(this.editor.refreshInDom) {
|
||||
this.editor.refreshInDom();
|
||||
}
|
||||
} else {
|
||||
// Refresh any children
|
||||
|
@ -156,11 +156,6 @@ BitmapEditor.prototype.saveChanges = function() {
|
||||
}
|
||||
};
|
||||
|
||||
BitmapEditor.prototype.isRefreshable = function() {
|
||||
// Don't ever refresh the bitmap editor
|
||||
return false;
|
||||
};
|
||||
|
||||
exports["image/jpg"] = BitmapEditor;
|
||||
exports["image/jpeg"] = BitmapEditor;
|
||||
exports["image/png"] = BitmapEditor;
|
||||
|
@ -18,7 +18,10 @@ function TextEditor(macroNode) {
|
||||
this.macroNode = macroNode;
|
||||
}
|
||||
|
||||
TextEditor.prototype.getChild = function() {
|
||||
/*
|
||||
Get the tiddler being editted, field name and current value
|
||||
*/
|
||||
TextEditor.prototype.getEditText = function() {
|
||||
// Get the current tiddler and the field name
|
||||
var tiddler = this.macroNode.wiki.getTiddler(this.macroNode.tiddlerTitle),
|
||||
field = this.macroNode.hasParameter("field") ? this.macroNode.params.field : "title",
|
||||
@ -40,19 +43,24 @@ TextEditor.prototype.getChild = function() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return {tiddler: tiddler, field: field, value: value};
|
||||
};
|
||||
|
||||
TextEditor.prototype.getChild = function() {
|
||||
var edit = this.getEditText();
|
||||
var attributes = {
|
||||
"class": ["tw-edit-field"]
|
||||
},
|
||||
tagName,
|
||||
content = [];
|
||||
// Make a textarea for text fields and an input box for other fields
|
||||
if(field === "text") {
|
||||
if(edit.field === "text") {
|
||||
tagName = "textarea";
|
||||
content.push($tw.Tree.Text(value));
|
||||
content.push($tw.Tree.Text(edit.value));
|
||||
} else {
|
||||
tagName = "input";
|
||||
attributes.type = "text";
|
||||
attributes.value = value;
|
||||
attributes.value = edit.value;
|
||||
}
|
||||
// Wrap the editor control in a div
|
||||
return $tw.Tree.Element("div",{},[$tw.Tree.Element(tagName,attributes,content)],{
|
||||
@ -92,7 +100,7 @@ TextEditor.prototype.fixHeight = function() {
|
||||
var prevWrapperHeight = wrapper.style.height;
|
||||
wrapper.style.height = textarea.style.height + "px";
|
||||
textarea.style.overflow = "hidden";
|
||||
textarea.style.height = "1px";
|
||||
// textarea.style.height = "1px";
|
||||
textarea.style.height = Math.max(textarea.scrollHeight,MIN_TEXT_AREA_HEIGHT) + "px";
|
||||
wrapper.style.height = prevWrapperHeight;
|
||||
}
|
||||
@ -102,9 +110,13 @@ TextEditor.prototype.postRenderInDom = function() {
|
||||
this.fixHeight();
|
||||
};
|
||||
|
||||
TextEditor.prototype.isRefreshable = function() {
|
||||
// Don't refresh the editor if it contains the caret or selection
|
||||
return document.activeElement !== this.macroNode.child.children[0].domNode;
|
||||
TextEditor.prototype.refreshInDom = function() {
|
||||
if(document.activeElement !== this.macroNode.child.children[0].domNode) {
|
||||
var edit = this.getEditText();
|
||||
this.macroNode.child.children[0].domNode.value = edit.value;
|
||||
}
|
||||
// Fix the height if needed
|
||||
this.fixHeight();
|
||||
};
|
||||
|
||||
exports["text/x-tiddlywiki"] = TextEditor;
|
||||
|
Loading…
x
Reference in New Issue
Block a user