mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fix constructing result note path in the jump to note dialog, closes #4054
This commit is contained in:
parent
08398a1417
commit
ddda4d9867
@ -19,20 +19,22 @@ class NoteFlatTextExp extends Expression {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {BNote} note
|
* @param {BNote} note
|
||||||
* @param {string[]} tokens
|
* @param {string[]} remainingTokens - tokens still needed to be found in the path towards root
|
||||||
* @param {string[]} path
|
* @param {string[]} takenPath - path so far taken towards from candidate note towards the root.
|
||||||
|
* It contains the suffix fragment of the full note path.
|
||||||
*/
|
*/
|
||||||
const searchDownThePath = (note, tokens, path) => {
|
const searchPathTowardsRoot = (note, remainingTokens, takenPath) => {
|
||||||
if (tokens.length === 0) {
|
if (remainingTokens.length === 0) {
|
||||||
const retPath = this.getNotePath(note, path);
|
// we're done, just build the result
|
||||||
|
const resultPath = this.getNotePath(note, takenPath);
|
||||||
|
|
||||||
if (retPath) {
|
if (resultPath) {
|
||||||
const noteId = retPath[retPath.length - 1];
|
const noteId = resultPath[resultPath.length - 1];
|
||||||
|
|
||||||
if (!resultNoteSet.hasNoteId(noteId)) {
|
if (!resultNoteSet.hasNoteId(noteId)) {
|
||||||
// we could get here from multiple paths, the first one wins because the paths
|
// we could get here from multiple paths, the first one wins because the paths
|
||||||
// are sorted by importance
|
// are sorted by importance
|
||||||
executionContext.noteIdToNotePath[noteId] = retPath;
|
executionContext.noteIdToNotePath[noteId] = resultPath;
|
||||||
|
|
||||||
resultNoteSet.add(becca.notes[noteId]);
|
resultNoteSet.add(becca.notes[noteId]);
|
||||||
}
|
}
|
||||||
@ -42,22 +44,23 @@ class NoteFlatTextExp extends Expression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (note.parents.length === 0 || note.noteId === 'root') {
|
if (note.parents.length === 0 || note.noteId === 'root') {
|
||||||
|
// we've reached root, but there are still remaining tokens -> this candidate note produced no result
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const foundAttrTokens = [];
|
const foundAttrTokens = [];
|
||||||
|
|
||||||
for (const token of tokens) {
|
for (const token of remainingTokens) {
|
||||||
if (note.type.includes(token) || note.mime.includes(token)) {
|
if (note.type.includes(token) || note.mime.includes(token)) {
|
||||||
foundAttrTokens.push(token);
|
foundAttrTokens.push(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const attribute of note.ownedAttributes) {
|
for (const attribute of note.getOwnedAttributes()) {
|
||||||
const normalizedName = utils.normalize(attribute.name);
|
const normalizedName = utils.normalize(attribute.name);
|
||||||
const normalizedValue = utils.normalize(attribute.value);
|
const normalizedValue = utils.normalize(attribute.value);
|
||||||
|
|
||||||
for (const token of tokens) {
|
for (const token of remainingTokens) {
|
||||||
if (normalizedName.includes(token) || normalizedValue.includes(token)) {
|
if (normalizedName.includes(token) || normalizedValue.includes(token)) {
|
||||||
foundAttrTokens.push(token);
|
foundAttrTokens.push(token);
|
||||||
}
|
}
|
||||||
@ -68,19 +71,19 @@ class NoteFlatTextExp extends Expression {
|
|||||||
const title = utils.normalize(beccaService.getNoteTitle(note.noteId, parentNote.noteId));
|
const title = utils.normalize(beccaService.getNoteTitle(note.noteId, parentNote.noteId));
|
||||||
const foundTokens = foundAttrTokens.slice();
|
const foundTokens = foundAttrTokens.slice();
|
||||||
|
|
||||||
for (const token of tokens) {
|
for (const token of remainingTokens) {
|
||||||
if (title.includes(token)) {
|
if (title.includes(token)) {
|
||||||
foundTokens.push(token);
|
foundTokens.push(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundTokens.length > 0) {
|
if (foundTokens.length > 0) {
|
||||||
const remainingTokens = tokens.filter(token => !foundTokens.includes(token));
|
const newRemainingTokens = remainingTokens.filter(token => !foundTokens.includes(token));
|
||||||
|
|
||||||
searchDownThePath(parentNote, remainingTokens, [...path, note.noteId]);
|
searchPathTowardsRoot(parentNote, newRemainingTokens, [note.noteId, ...takenPath]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
searchDownThePath(parentNote, tokens, [...path, note.noteId]);
|
searchPathTowardsRoot(parentNote, remainingTokens, [note.noteId, ...takenPath]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +93,7 @@ class NoteFlatTextExp extends Expression {
|
|||||||
for (const note of candidateNotes) {
|
for (const note of candidateNotes) {
|
||||||
// autocomplete should be able to find notes by their noteIds as well (only leafs)
|
// autocomplete should be able to find notes by their noteIds as well (only leafs)
|
||||||
if (this.tokens.length === 1 && note.noteId.toLowerCase() === this.tokens[0]) {
|
if (this.tokens.length === 1 && note.noteId.toLowerCase() === this.tokens[0]) {
|
||||||
searchDownThePath(note, [], []);
|
searchPathTowardsRoot(note, [], [note.noteId]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +126,7 @@ class NoteFlatTextExp extends Expression {
|
|||||||
if (foundTokens.length > 0) {
|
if (foundTokens.length > 0) {
|
||||||
const remainingTokens = this.tokens.filter(token => !foundTokens.includes(token));
|
const remainingTokens = this.tokens.filter(token => !foundTokens.includes(token));
|
||||||
|
|
||||||
searchDownThePath(parentNote, remainingTokens, [note.noteId]);
|
searchPathTowardsRoot(parentNote, remainingTokens, [note.noteId]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,14 +134,22 @@ class NoteFlatTextExp extends Expression {
|
|||||||
return resultNoteSet;
|
return resultNoteSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
getNotePath(note, path) {
|
/**
|
||||||
if (path.length === 0) {
|
* @param {BNote} note
|
||||||
|
* @param {string[]} takenPath
|
||||||
|
* @returns {string[]}
|
||||||
|
*/
|
||||||
|
getNotePath(note, takenPath) {
|
||||||
|
if (takenPath.length === 0) {
|
||||||
|
throw new Error("Path is not expected to be empty.");
|
||||||
|
} else if (takenPath.length === 1 && takenPath[0] === note.noteId) {
|
||||||
return note.getBestNotePath();
|
return note.getBestNotePath();
|
||||||
} else {
|
} else {
|
||||||
const closestNoteId = path[0];
|
// this note is the closest to root containing the last matching token(s), thus completing the requirements
|
||||||
const closestNoteBestNotePath = becca.getNote(closestNoteId).getBestNotePath();
|
// what's in this note's predecessors does not matter, thus we'll choose the best note path
|
||||||
|
const topMostMatchingTokenNotePath = becca.getNote(takenPath[0]).getBestNotePath();
|
||||||
|
|
||||||
return [...closestNoteBestNotePath, ...path.slice(1)];
|
return [...topMostMatchingTokenNotePath, ...takenPath.slice(1)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user