mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Fix setTextReference()
It wasn’t working for non-existent tiddlers. Also added support for setting indexed properties of a data tiddler.
This commit is contained in:
parent
9bd0174205
commit
8e17c1dfd5
@ -54,21 +54,18 @@ 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;
|
||||
// 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()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.deleteTextReference = function(textRef,currTiddlerTitle) {
|
||||
|
Loading…
Reference in New Issue
Block a user