From 8e17c1dfd59d03702e043f2f55b7c9068c3b87fa Mon Sep 17 00:00:00 2001 From: Jermolene Date: Wed, 12 Mar 2014 21:54:43 +0000 Subject: [PATCH] Fix setTextReference() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It wasn’t working for non-existent tiddlers. Also added support for setting indexed properties of a data tiddler. --- core/modules/wiki.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/core/modules/wiki.js b/core/modules/wiki.js index b211b22aa..4b62f3bfa 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -54,20 +54,17 @@ exports.getTextReference = function(textRef,defaultText,currTiddlerTitle) { exports.setTextReference = function(textRef,value,currTiddlerTitle) { var tr = $tw.utils.parseTextReference(textRef), - title,tiddler,fields; - // Check if it is a reference to a tiddler - if(tr.title && !tr.field) { - tiddler = this.getTiddler(tr.title); - this.addTiddler(new $tw.Tiddler(tiddler,{title: tr.title,text: value},this.getModificationFields())); - // Else check for a field reference - } else if(tr.field) { title = tr.title || currTiddlerTitle; - tiddler = this.getTiddler(title); - if(tiddler) { - fields = {}; - fields[tr.field] = value; - this.addTiddler(new $tw.Tiddler(tiddler,fields,this.getModificationFields())); - } + // Check if it is a reference to a tiddler field + if(tr.index) { + var data = this.getTiddlerData(title,{}); + data[tr.index] = value; + this.setTiddlerData(title,data,this.getModificationFields()); + } else { + var tiddler = this.getTiddler(title), + fields = {title: title}; + fields[tr.field || "text"] = value; + this.addTiddler(new $tw.Tiddler(tiddler,fields,this.getModificationFields())); } };