mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-23 17:58:45 +00:00
allow unusedtitle macro to use the prefix parameter and fix wiki.generateNewTitle() (#5361)
This commit is contained in:
+15
-5
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user