allow unusedtitle macro to use the prefix parameter and fix wiki.generateNewTitle() (#5361)

This commit is contained in:
Mario Pietsch
2021-05-02 19:26:50 +01:00
committed by GitHub
parent 3f98686153
commit cf56a17f28
6 changed files with 154 additions and 18 deletions
+15 -5
View File
@@ -190,15 +190,25 @@ exports.getChangeCount = function(title) {
/*
Generate an unused title from the specified base
options.prefix must be a string
*/
exports.generateNewTitle = function(baseTitle,options) {
options = options || {};
var c = 0,
title = baseTitle;
while(this.tiddlerExists(title) || this.isShadowTiddler(title) || this.findDraft(title)) {
title = baseTitle +
(options.prefix || " ") +
(++c);
title = baseTitle,
template = options.template,
prefix = (typeof(options.prefix) === "string") ? options.prefix : " ";
if (template) {
// "count" is important to avoid an endless loop in while(...)!!
template = (/\$count:?(\d+)?\$/i.test(template)) ? template : template + "$count$";
title = $tw.utils.formatTitleString(template,{"base":baseTitle,"separator":prefix,"counter":c});
while(this.tiddlerExists(title) || this.isShadowTiddler(title) || this.findDraft(title)) {
title = $tw.utils.formatTitleString(template,{"base":baseTitle,"separator":prefix,"counter":(++c)});
}
} else {
while(this.tiddlerExists(title) || this.isShadowTiddler(title) || this.findDraft(title)) {
title = baseTitle + prefix + (++c);
}
}
return title;
};