From f999b2e9316959908d6ac0a81490d14e5d521e08 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Sat, 31 May 2014 18:37:27 +0100 Subject: [PATCH] Add wiki.setText() method --- core/modules/wiki.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/modules/wiki.js b/core/modules/wiki.js index daf61ecc5..0bae67fca 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -55,15 +55,19 @@ exports.getTextReference = function(textRef,defaultText,currTiddlerTitle) { exports.setTextReference = function(textRef,value,currTiddlerTitle) { var tr = $tw.utils.parseTextReference(textRef), title = tr.title || currTiddlerTitle; + this.setText(title,tr.field,tr.index,value); +}; + +exports.setText = function(title,field,index,value) { // Check if it is a reference to a tiddler field - if(tr.index) { + if(index) { var data = this.getTiddlerData(title,Object.create(null)); - data[tr.index] = value; + data[index] = value; this.setTiddlerData(title,data,this.getModificationFields()); } else { var tiddler = this.getTiddler(title), fields = {title: title}; - fields[tr.field || "text"] = value; + fields[field || "text"] = value; this.addTiddler(new $tw.Tiddler(tiddler,fields,this.getModificationFields())); } };