Skip to content

Build your personal knowledge base with Trilium Notes

search note fixes

azivnerbd913a63a87f
diff --git a/src/public/images/icons/save.png b/src/public/images/icons/save.png
new file mode 100644
index 0000000000..4fd62aaf2e
Binary files /dev/null and b/src/public/images/icons/save.png differ
diff --git a/src/public/javascripts/services/context_menu.js b/src/public/javascripts/services/context_menu.js
index 2c19561c45..29a5fd5001 100644
--- a/src/public/javascripts/services/context_menu.js
+++ b/src/public/javascripts/services/context_menu.js
@@ -114,13 +114,14 @@ const contextMenuOptions = {
// Modify menu entries depending on node status
$tree.contextmenu("enableEntry", "insertNoteHere", isNotRoot && parentNote.type !== 'search');
$tree.contextmenu("enableEntry", "insertChildNote", note.type !== 'search');
- $tree.contextmenu("enableEntry", "delete", isNotRoot);
+ $tree.contextmenu("enableEntry", "delete", isNotRoot && parentNote.type !== 'search');
$tree.contextmenu("enableEntry", "copy", isNotRoot);
$tree.contextmenu("enableEntry", "cut", isNotRoot);
$tree.contextmenu("enableEntry", "pasteAfter", clipboardIds.length > 0 && isNotRoot && parentNote.type !== 'search');
$tree.contextmenu("enableEntry", "pasteInto", clipboardIds.length > 0 && note.type !== 'search');
$tree.contextmenu("enableEntry", "importBranch", note.type !== 'search');
$tree.contextmenu("enableEntry", "exportBranch", note.type !== 'search');
+ $tree.contextmenu("enableEntry", "editBranchPrefix", parentNote.type !== 'search');
// Activate node on right-click
node.setActive();
diff --git a/src/public/javascripts/services/tree_builder.js b/src/public/javascripts/services/tree_builder.js
index 68dede509a..813233c5c7 100644
--- a/src/public/javascripts/services/tree_builder.js
+++ b/src/public/javascripts/services/tree_builder.js
@@ -74,14 +74,14 @@ async function prepareRealBranch(parentNote) {
async function prepareSearchBranch(note) {
const fullNote = await noteDetailService.loadNote(note.noteId);
- const noteIds = await server.get('search/' + encodeURIComponent(fullNote.jsonContent.searchString));
+ const results = await server.get('search/' + encodeURIComponent(fullNote.jsonContent.searchString));
- for (const noteId of noteIds) {
+ for (const result of results) {
const branch = new Branch(treeCache, {
branchId: "virt" + utils.randomString(10),
- noteId: noteId,
+ noteId: result.noteId,
parentNoteId: note.noteId,
- prefix: '',
+ prefix: result.prefix,
virtual: true
});
diff --git a/src/services/note_cache.js b/src/services/note_cache.js
index 6873762601..cf284c796f 100644
--- a/src/services/note_cache.js
+++ b/src/services/note_cache.js
@@ -8,6 +8,7 @@ const utils = require('./utils');
let noteTitles;
let protectedNoteTitles;
let noteIds;
+let childParentToBranchId = {};
const childToParent = {};
const hideInAutocomplete = {};
@@ -20,11 +21,12 @@ async function load() {
prefixes = await sql.getMap(`SELECT noteId || '-' || parentNoteId, prefix FROM branches WHERE prefix IS NOT NULL AND prefix != ''`);
- const relations = await sql.getRows(`SELECT noteId, parentNoteId FROM branches WHERE isDeleted = 0`);
+ const relations = await sql.getRows(`SELECT branchId, noteId, parentNoteId FROM branches WHERE isDeleted = 0`);
for (const rel of relations) {
childToParent[rel.noteId] = childToParent[rel.noteId] || [];
childToParent[rel.noteId].push(rel.parentNoteId);
+ childParentToBranchId[`${rel.noteId}-${rel.parentNoteId}`] = rel.branchId;
}
const hiddenLabels = await sql.getColumn(`SELECT noteId FROM labels WHERE isDeleted = 0 AND name = 'hideInAutocomplete'`);
@@ -91,11 +93,15 @@ function search(noteId, tokens, path, results) {
if (retPath) {
const noteTitle = getNoteTitleForPath(retPath);
+ const thisNoteId = retPath[retPath.length - 1];
+ const thisParentNoteId = retPath[retPath.length - 2];
results.push({
- noteId: noteId,
+ noteId: thisNoteId,
+ branchId: childParentToBranchId[`${thisNoteId}-${thisParentNoteId}`],
title: noteTitle,
- path: retPath.join('/')
+ path: retPath.join('/'),
+ prefix: prefixes[`${thisNoteId}-${thisParentNoteId}`]
});
}
@@ -230,6 +236,7 @@ eventService.subscribe(eventService.ENTITY_CHANGED, async ({entityName, entityId
if (branch.isDeleted) {
delete prefixes[branch.noteId + '-' + branch.parentNoteId];
+ delete childParentToBranchId[branch.noteId + '-' + branch.parentNoteId];
}
else {
if (branch.prefix) {
@@ -238,6 +245,7 @@ eventService.subscribe(eventService.ENTITY_CHANGED, async ({entityName, entityId
childToParent[branch.noteId] = childToParent[branch.noteId] || [];
childToParent[branch.noteId].push(branch.parentNoteId);
+ childParentToBranchId[branch.noteId + '-' + branch.parentNoteId] = branch.branchId;
}
}
else if (entityName === 'labels') {
diff --git a/src/views/index.ejs b/src/views/index.ejs
index 1830ae6508..8ca85ea7bf 100644
--- a/src/views/index.ejs
+++ b/src/views/index.ejs
@@ -77,7 +77,12 @@
<div style="display: flex; align-items: center;">
<input name="search-text" placeholder="Search text, labels" style="flex-grow: 100; margin-left: 5px; margin-right: 5px;" autocomplete="off">
<button id="do-search-button" class="btn btn-sm" title="Search">Search</button>
- <button id="save-search-button" class="btn btn-sm" title="Save search">Save</button>
+
+ &nbsp;
+
+ <button id="save-search-button" class="btn btn-sm" title="Save search" style="padding: 4px;">
+ <img src="/images/icons/save.png" alt="Save search"/>
+ </button>
</div>
</div>
@@ -115,10 +120,10 @@
<div class="btn-group btn-group-xs">
<button type="button" class="btn" id="protect-button" title="Protected note can be viewed and edited only after entering password">
- <img src="images/icons/shield.png"/>
+ <img src="/images/icons/shield.png"/>
</button>
<button type="button" class="btn" id="unprotect-button" title="Not protected note can be viewed without entering password">
- <img src="images/icons/shield-off.png"/>
+ <img src="/images/icons/shield-off.png"/>
</button>
</div>
</div>