mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 12:07:19 +00:00
Add wiki.setText() method
This commit is contained in:
parent
4d70d5780e
commit
f999b2e931
@ -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()));
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user