Skip to content

Build your personal knowledge base with Trilium Notes

allow refreshing saved note, closes #304

azivnerc8ec86e5379f
diff --git a/src/public/javascripts/services/note_detail_search.js b/src/public/javascripts/services/note_detail_search.js
index 6e347cffc2..9a4d8c8f69 100644
--- a/src/public/javascripts/services/note_detail_search.js
+++ b/src/public/javascripts/services/note_detail_search.js
@@ -1,7 +1,9 @@
import noteDetailService from "./note_detail.js";
+import treeService from "./tree.js";
const $searchString = $("#search-string");
const $component = $('#note-detail-search');
+const $refreshButton = $('#note-detail-search-refresh-results-button');
function getContent() {
return JSON.stringify({
@@ -25,6 +27,8 @@ function show() {
$searchString.on('input', noteDetailService.noteChanged);
}
+$refreshButton.click(() => treeService.reload());
+
export default {
getContent,
show,
diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js
index 8be2a0b9cf..2245996a54 100644
--- a/src/public/javascripts/services/tree.js
+++ b/src/public/javascripts/services/tree.js
@@ -352,6 +352,7 @@ function clearSelectedNodes() {
}
async function treeInitialized() {
+ // - is used in mobile to indicate that we don't want to activate any note after load
if (startNotePath === '-') {
return;
}
@@ -363,7 +364,6 @@ async function treeInitialized() {
startNotePath = null;
}
- // - is used in mobile to indicate that we don't want to activate any note after load
if (startNotePath) {
const node = await activateNote(startNotePath);
@@ -438,6 +438,16 @@ function initFancyTree(tree) {
$span.append(unhoistButton);
}
+ },
+ // this is done to automatically lazy load all expanded search notes after tree load
+ loadChildren: function(event, data) {
+ data.node.visit(function(subNode){
+ // Load all lazy/unloaded child nodes
+ // (which will trigger `loadChildren` recursively)
+ if( subNode.isUndefined() && subNode.isExpanded() ) {
+ subNode.load();
+ }
+ });
}
});
diff --git a/src/public/javascripts/services/tree_builder.js b/src/public/javascripts/services/tree_builder.js
index 2fc6a2c2ef..cee322481c 100644
--- a/src/public/javascripts/services/tree_builder.js
+++ b/src/public/javascripts/services/tree_builder.js
@@ -86,7 +86,7 @@ async function prepareNode(branch) {
extraClasses: await getExtraClasses(note),
icon: await getIcon(note),
refKey: note.noteId,
- expanded: (note.type !== 'search' && branch.isExpanded) || hoistedNoteId === note.noteId
+ expanded: branch.isExpanded || hoistedNoteId === note.noteId
};
if (note.hasChildren() || note.type === 'search') {
diff --git a/src/views/details/search.ejs b/src/views/details/search.ejs
index a741a0c99b..2fa424990c 100644
--- a/src/views/details/search.ejs
+++ b/src/views/details/search.ejs
@@ -1,7 +1,12 @@
<div id="note-detail-search" class="note-detail-component">
<div style="display: flex; align-items: center;">
<strong>Search string: &nbsp; &nbsp;</strong>
- <textarea rows="4" cols="50" id="search-string"></textarea>
+ <textarea rows="4" cols="40" id="search-string"></textarea>
+
+ <span>
+ &nbsp; &nbsp;
+ <button type="button" class="btn btn-primary" id="note-detail-search-refresh-results-button">Refresh tree</button>
+ </span>
</div>
<br />