mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-31 15:42:59 +00:00 
			
		
		
		
	Refactored editor logic to handle refreshes more efficiently
This commit is contained in:
		| @@ -50,16 +50,8 @@ exports.refreshInDom = function(changes) { | |||||||
| 	var t; | 	var t; | ||||||
| 	// Only refresh if a dependency is triggered | 	// Only refresh if a dependency is triggered | ||||||
| 	if(this.dependencies.hasChanged(changes,this.tiddlerTitle)) { | 	if(this.dependencies.hasChanged(changes,this.tiddlerTitle)) { | ||||||
| 		// Only refresh if the editor lets us | 		if(this.editor.refreshInDom) { | ||||||
| 		if(this.editor.isRefreshable()) { | 			this.editor.refreshInDom(); | ||||||
| 			// 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); |  | ||||||
| 		} | 		} | ||||||
| 	} else { | 	} else { | ||||||
| 		// Refresh any children | 		// 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/jpg"] = BitmapEditor; | ||||||
| exports["image/jpeg"] = BitmapEditor; | exports["image/jpeg"] = BitmapEditor; | ||||||
| exports["image/png"] = BitmapEditor; | exports["image/png"] = BitmapEditor; | ||||||
|   | |||||||
| @@ -18,7 +18,10 @@ function TextEditor(macroNode) { | |||||||
| 	this.macroNode = 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 | 	// Get the current tiddler and the field name | ||||||
| 	var tiddler = this.macroNode.wiki.getTiddler(this.macroNode.tiddlerTitle), | 	var tiddler = this.macroNode.wiki.getTiddler(this.macroNode.tiddlerTitle), | ||||||
| 		field = this.macroNode.hasParameter("field") ? this.macroNode.params.field : "title", | 		field = this.macroNode.hasParameter("field") ? this.macroNode.params.field : "title", | ||||||
| @@ -40,19 +43,24 @@ TextEditor.prototype.getChild = function() { | |||||||
| 				break; | 				break; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 	return {tiddler: tiddler, field: field, value: value}; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | TextEditor.prototype.getChild = function() { | ||||||
|  | 	var edit = this.getEditText(); | ||||||
| 	var attributes = { | 	var attributes = { | ||||||
| 			"class": ["tw-edit-field"] | 			"class": ["tw-edit-field"] | ||||||
| 		}, | 		}, | ||||||
| 		tagName, | 		tagName, | ||||||
| 		content = []; | 		content = []; | ||||||
| 	// Make a textarea for text fields and an input box for other fields | 	// Make a textarea for text fields and an input box for other fields | ||||||
| 	if(field === "text") { | 	if(edit.field === "text") { | ||||||
| 		tagName = "textarea"; | 		tagName = "textarea"; | ||||||
| 		content.push($tw.Tree.Text(value)); | 		content.push($tw.Tree.Text(edit.value)); | ||||||
| 	} else { | 	} else { | ||||||
| 		tagName = "input"; | 		tagName = "input"; | ||||||
| 		attributes.type = "text"; | 		attributes.type = "text"; | ||||||
| 		attributes.value = value; | 		attributes.value = edit.value; | ||||||
| 	} | 	} | ||||||
| 	// Wrap the editor control in a div | 	// Wrap the editor control in a div | ||||||
| 	return $tw.Tree.Element("div",{},[$tw.Tree.Element(tagName,attributes,content)],{ | 	return $tw.Tree.Element("div",{},[$tw.Tree.Element(tagName,attributes,content)],{ | ||||||
| @@ -92,7 +100,7 @@ TextEditor.prototype.fixHeight = function() { | |||||||
| 		var prevWrapperHeight = wrapper.style.height; | 		var prevWrapperHeight = wrapper.style.height; | ||||||
| 		wrapper.style.height = textarea.style.height + "px"; | 		wrapper.style.height = textarea.style.height + "px"; | ||||||
| 		textarea.style.overflow = "hidden"; | 		textarea.style.overflow = "hidden"; | ||||||
| 		textarea.style.height = "1px"; | //		textarea.style.height = "1px"; | ||||||
| 		textarea.style.height = Math.max(textarea.scrollHeight,MIN_TEXT_AREA_HEIGHT) + "px"; | 		textarea.style.height = Math.max(textarea.scrollHeight,MIN_TEXT_AREA_HEIGHT) + "px"; | ||||||
| 		wrapper.style.height = prevWrapperHeight; | 		wrapper.style.height = prevWrapperHeight; | ||||||
| 	} | 	} | ||||||
| @@ -102,9 +110,13 @@ TextEditor.prototype.postRenderInDom = function() { | |||||||
| 	this.fixHeight(); | 	this.fixHeight(); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| TextEditor.prototype.isRefreshable = function() { | TextEditor.prototype.refreshInDom = function() { | ||||||
| 	// Don't refresh the editor if it contains the caret or selection | 	if(document.activeElement !== this.macroNode.child.children[0].domNode) { | ||||||
| 	return 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; | exports["text/x-tiddlywiki"] = TextEditor; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jeremy Ruston
					Jeremy Ruston