mirror of
https://github.com/zadam/trilium.git
synced 2025-01-15 19:51:57 +08:00
Fix: Highlighting searched term should ignore accents (#2364)
* fixed accent highlighting not working * fixed * fixes * improvements
This commit is contained in:
parent
886fdf7cd6
commit
b23ead8097
4 changed files with 27 additions and 11 deletions
5
package-lock.json
generated
5
package-lock.json
generated
|
@ -6009,6 +6009,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
||||||
"integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA=="
|
"integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA=="
|
||||||
},
|
},
|
||||||
|
"normalize-strings": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/normalize-strings/-/normalize-strings-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-fARPRdTwmrQDLYhmeh7j/eZwrCP6WzxD6uKOdK/hT/uKACAE9AG2Bc2dgqOZLkfmmctHpfcJ9w3AQnfLgg3GYg=="
|
||||||
|
},
|
||||||
"normalize-url": {
|
"normalize-url": {
|
||||||
"version": "4.5.1",
|
"version": "4.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.1.tgz",
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
"mime-types": "2.1.34",
|
"mime-types": "2.1.34",
|
||||||
"multer": "1.4.3",
|
"multer": "1.4.3",
|
||||||
"node-abi": "3.5.0",
|
"node-abi": "3.5.0",
|
||||||
|
"normalize-strings": "^1.1.1",
|
||||||
"open": "8.4.0",
|
"open": "8.4.0",
|
||||||
"portscanner": "2.2.0",
|
"portscanner": "2.2.0",
|
||||||
"rand-token": "1.0.1",
|
"rand-token": "1.0.1",
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const normalizeString = require("normalize-strings");
|
||||||
const lex = require('./lex');
|
const lex = require('./lex');
|
||||||
const handleParens = require('./handle_parens');
|
const handleParens = require('./handle_parens');
|
||||||
const parse = require('./parse');
|
const parse = require('./parse');
|
||||||
|
@ -83,12 +84,8 @@ function findResultsWithExpression(expression, searchContext) {
|
||||||
throw new Error(`Can't find note path for note ${JSON.stringify(note.getPojo())}`);
|
throw new Error(`Can't find note path for note ${JSON.stringify(note.getPojo())}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notePathArray.includes("hidden")) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new SearchResult(notePathArray);
|
return new SearchResult(notePathArray);
|
||||||
}).filter(Boolean);
|
});
|
||||||
|
|
||||||
for (const res of searchResults) {
|
for (const res of searchResults) {
|
||||||
res.computeScore(searchContext.highlightedTokens);
|
res.computeScore(searchContext.highlightedTokens);
|
||||||
|
@ -222,11 +219,19 @@ function highlightSearchResults(searchResults, highlightedTokens) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const token of highlightedTokens) {
|
for (const token of highlightedTokens) {
|
||||||
// this approach won't work for strings with diacritics
|
|
||||||
const tokenRegex = new RegExp("(" + utils.escapeRegExp(token) + ")", "gi");
|
|
||||||
|
|
||||||
for (const result of searchResults) {
|
for (const result of searchResults) {
|
||||||
result.highlightedNotePathTitle = result.highlightedNotePathTitle.replace(tokenRegex, "{$1}");
|
// Reset token
|
||||||
|
const tokenRegex = new RegExp(utils.escapeRegExp(token), "gi");
|
||||||
|
let match;
|
||||||
|
|
||||||
|
// Find all matches
|
||||||
|
while ((match = tokenRegex.exec(normalizeString(result.highlightedNotePathTitle))) !== null) {
|
||||||
|
console.log(match)
|
||||||
|
result.highlightedNotePathTitle = utils.wrapText(result.highlightedNotePathTitle, match.index, token.length, "{", "}");
|
||||||
|
|
||||||
|
// 2 characters are added, so we need to adjust the index
|
||||||
|
tokenRegex.lastIndex += 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -264,7 +264,7 @@ function timeLimit(promise, limitMs, errorMessage) {
|
||||||
|
|
||||||
res(result);
|
res(result);
|
||||||
})
|
})
|
||||||
.catch(error => rej(error));
|
.catch(error => rej(error));
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!resolved) {
|
if (!resolved) {
|
||||||
|
@ -302,6 +302,10 @@ function filterAttributeName(name) {
|
||||||
return name.replace(/[^\p{L}\p{N}_:]/ug, "");
|
return name.replace(/[^\p{L}\p{N}_:]/ug, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wrapText(text, start, length, prefix, suffix) {
|
||||||
|
return text.substring(0, start) + prefix + text.substr(start, length) + suffix + text.substring(start + length);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
randomSecureToken,
|
randomSecureToken,
|
||||||
randomString,
|
randomString,
|
||||||
|
@ -336,5 +340,6 @@ module.exports = {
|
||||||
deferred,
|
deferred,
|
||||||
removeDiacritic,
|
removeDiacritic,
|
||||||
normalize,
|
normalize,
|
||||||
filterAttributeName
|
filterAttributeName,
|
||||||
|
wrapText
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue