Skip to content

Build your personal knowledge base with Trilium Notes

hiding the search resets filtering, showing gives focus to input box

azivnerbd7be9a8fd25
diff --git a/TODO b/TODO
index ef2f9e593a..8730ffefcd 100644
--- a/TODO
+++ b/TODO
@@ -21,6 +21,7 @@ Encryption:
Bugs:
- deleting cloned nodes ends with 500 (probably only on folders)
+- Uncaught Error: cannot call methods on fancytree prior to initialization; attempted to call method 'getTree'
Others:
- dates should be stored in UTC to work correctly with time zones
diff --git a/static/js/tree.js b/static/js/tree.js
index ea59a6f86f..eb30fdfd16 100644
--- a/static/js/tree.js
+++ b/static/js/tree.js
@@ -171,40 +171,14 @@ $(function(){
});
});
-$("input[name=search]").keyup(function (e) {
- const searchString = $(this).val();
-
- if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(searchString) === "") {
- $("button#btnResetSearch").click();
- return;
- }
-
- if (e && e.which === $.ui.keyCode.ENTER) {
- $.get(baseApiUrl + 'notes?search=' + searchString).then(resp => {
- console.log("search: ", resp);
-
- // Pass a string to perform case insensitive matching
- const tree = globalTree.fancytree("getTree");
- tree.filterBranches(function(node) {
- return resp.includes(node.data.note_id);
- });
- });
- }
-}).focus();
-
-$("button#btnResetSearch").click(function () {
- $("input[name=search]").val("");
-
- const tree = globalTree.fancytree("getTree");
- tree.clearFilter();
-});
-
function collapseTree() {
globalTree.fancytree("getRootNode").visit(function(node){
node.setExpanded(false);
});
}
+$(document).bind('keydown', 'alt+c', collapseTree);
+
function scrollToCurrentNote() {
const node = getNodeByKey(globalCurrentNote.detail.note_id);
@@ -215,14 +189,51 @@ function scrollToCurrentNote() {
}
}
-$(document).bind('keydown', 'alt+s', function() {
+function showSearch() {
$("#search-box").show();
$("input[name=search]").focus();
-});
+}
+
+$(document).bind('keydown', 'alt+s', showSearch);
function toggleSearch() {
- $("#search-box").toggle();
+ if ($("#search-box:hidden").length) {
+ showSearch();
+ }
+ else {
+ resetSearch();
+
+ $("#search-box").hide();
+ }
}
-$(document).bind('keydown', 'alt+c', collapseTree);
\ No newline at end of file
+function resetSearch() {
+ $("input[name=search]").val("");
+
+ const tree = globalTree.fancytree("getTree");
+ tree.clearFilter();
+}
+
+$("button#btnResetSearch").click(resetSearch);
+
+$("input[name=search]").keyup(function (e) {
+ const searchString = $(this).val();
+
+ if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(searchString) === "") {
+ $("button#btnResetSearch").click();
+ return;
+ }
+
+ if (e && e.which === $.ui.keyCode.ENTER) {
+ $.get(baseApiUrl + 'notes?search=' + searchString).then(resp => {
+ console.log("search: ", resp);
+
+ // Pass a string to perform case insensitive matching
+ const tree = globalTree.fancytree("getTree");
+ tree.filterBranches(function(node) {
+ return resp.includes(node.data.note_id);
+ });
+ });
+ }
+}).focus();
\ No newline at end of file