mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-11 18:00:26 +00:00
Fix problem with wiki.search() incorrectly searching missing tiddlers
This commit is contained in:
parent
86f0128e83
commit
df0a1a7c42
@ -724,24 +724,29 @@ exports.search = function(text,options) {
|
|||||||
flags = options.caseSensitive ? "" : "i";
|
flags = options.caseSensitive ? "" : "i";
|
||||||
if(options.literal) {
|
if(options.literal) {
|
||||||
if(text.length === 0) {
|
if(text.length === 0) {
|
||||||
return [];
|
searchTermsRegExps = null;
|
||||||
|
} else {
|
||||||
|
searchTermsRegExps = [new RegExp("(" + $tw.utils.escapeRegExp(text) + ")",flags)];
|
||||||
}
|
}
|
||||||
searchTermsRegExps = [new RegExp("(" + $tw.utils.escapeRegExp(text) + ")",flags)];
|
|
||||||
} else {
|
} else {
|
||||||
terms = text.replace(/( +)/g," ").split(" ");
|
terms = text.replace(/( +)/g," ").split(" ");
|
||||||
searchTermsRegExps = [];
|
if(terms.length === 1 && terms[0] === "") {
|
||||||
if(terms.length === 0) {
|
searchTermsRegExps = null;
|
||||||
return [];
|
} else {
|
||||||
}
|
searchTermsRegExps = [];
|
||||||
for(t=0; t<terms.length; t++) {
|
for(t=0; t<terms.length; t++) {
|
||||||
searchTermsRegExps.push(new RegExp("(" + $tw.utils.escapeRegExp(terms[t]) + ")",flags));
|
searchTermsRegExps.push(new RegExp("(" + $tw.utils.escapeRegExp(terms[t]) + ")",flags));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Function to check a given tiddler for the search term
|
// Function to check a given tiddler for the search term
|
||||||
var searchTiddler = function(title) {
|
var searchTiddler = function(title) {
|
||||||
|
if(!searchTermsRegExps) {
|
||||||
|
return !options.invert;
|
||||||
|
}
|
||||||
var tiddler = self.getTiddler(title);
|
var tiddler = self.getTiddler(title);
|
||||||
if(!tiddler) {
|
if(!tiddler) {
|
||||||
return !!options.invert;
|
tiddler = new $tw.Tiddler({title: title, text: "", type: "text/vnd.tiddlywiki"});
|
||||||
}
|
}
|
||||||
var contentTypeInfo = $tw.config.contentTypeInfo[tiddler.fields.type];
|
var contentTypeInfo = $tw.config.contentTypeInfo[tiddler.fields.type];
|
||||||
if(contentTypeInfo ? contentTypeInfo.encoding === "utf8" : true) {
|
if(contentTypeInfo ? contentTypeInfo.encoding === "utf8" : true) {
|
||||||
|
Loading…
Reference in New Issue
Block a user