Skip to content

Build your personal knowledge base with Trilium Notes

fixed tree hotkeys

zadamfbe3995398fc
diff --git a/libraries/jquery.fancytree.hotkeys.js b/libraries/jquery.fancytree.hotkeys.js
deleted file mode 100644
index e19e16d858..0000000000
--- a/libraries/jquery.fancytree.hotkeys.js
+++ /dev/null
@@ -1,35 +0,0 @@
-/**!
- * jquery.fancytree.hotkeys.js
- *
- * Integrate the 'jQuery.Hotkeys' plugin as Fancytree extension:
- * https://github.com/jeresig/jquery.hotkeys/
- *
- * Copyright (c) 2008-2017, Martin Wendt (http://wwWendt.de)
- * Released under the MIT license
- * https://github.com/mar10/fancytree/wiki/LicenseInfo
- */
-(function($, document) {
- "use strict";
-
- var initHotkeys = function(tree, data) {
- $.each(data, function(event, keys) {
- $.each(keys, function(key, handler) {
- $(tree.$container).on(event, null, key, function(evt) {
- var node = tree.getActiveNode();
- return handler(node, evt);
- // return false from the handler will stop default handling.
- });
- });
- });
- };
-
- $.ui.fancytree.registerExtension({
- name: "hotkeys",
- version: "@VERSION",
- hotkeys: { },
- treeInit: function(ctx) {
- this._superApply(arguments);
- initHotkeys(this, ctx.options.hotkeys);
- }
- });
-}(jQuery, document));
diff --git a/src/public/app/services/app_context.js b/src/public/app/services/app_context.js
index 6a06ea9f88..f2190c537c 100644
--- a/src/public/app/services/app_context.js
+++ b/src/public/app/services/app_context.js
@@ -28,8 +28,6 @@ class AppContext extends Component {
async start() {
await Promise.all([treeCache.initializedPromise, options.initializedPromise]);
- $("#loading-indicator").hide();
-
this.showWidgets();
this.tabManager.loadTabs();
diff --git a/src/public/app/services/utils.js b/src/public/app/services/utils.js
index 136080305c..f70acd63b1 100644
--- a/src/public/app/services/utils.js
+++ b/src/public/app/services/utils.js
@@ -1,5 +1,5 @@
function reloadApp() {
- window.location.reload(true);
+ //window.location.reload(true);
}
function parseDate(str) {
diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js
index 3626bc032b..c1d42aa382 100644
--- a/src/public/app/widgets/note_tree.js
+++ b/src/public/app/widgets/note_tree.js
@@ -303,7 +303,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
this.$tree.fancytree({
titlesTabbable: true,
keyboard: true,
- extensions: utils.isMobile() ? ["dnd5", "clones"] : ["hotkeys", "dnd5", "clones"],
+ extensions: ["dnd5", "clones"],
source: treeData,
scrollOfs: {
top: 100,
@@ -354,7 +354,6 @@ export default class NoteTreeWidget extends TabAwareWidget {
},
expand: (event, data) => this.setExpanded(data.node.data.branchId, true),
collapse: (event, data) => this.setExpanded(data.node.data.branchId, false),
- //hotkeys: utils.isMobile() ? undefined : { keydown: await this.getHotKeys() },
dnd5: {
autoExpandMS: 600,
dragStart: (node, data) => {
@@ -457,27 +456,27 @@ export default class NoteTreeWidget extends TabAwareWidget {
clones: {
highlightActiveClones: true
},
- // enhanceTitle: async function (event, data) {
- // const node = data.node;
- // const $span = $(node.span);
- //
- // if (node.data.noteId !== 'root'
- // && node.data.noteId === hoistedNoteService.getHoistedNoteId()
- // && $span.find('.unhoist-button').length === 0) {
- //
- // const unhoistButton = $('<span>&nbsp; (<a class="unhoist-button">unhoist</a>)</span>');
- //
- // $span.append(unhoistButton);
- // }
- //
- // const note = await treeCache.getNote(node.data.noteId);
- //
- // if (note.type === 'search' && $span.find('.refresh-search-button').length === 0) {
- // const refreshSearchButton = $('<span>&nbsp; <span class="refresh-search-button bx bx-refresh" title="Refresh saved search results"></span></span>');
- //
- // $span.append(refreshSearchButton);
- // }
- // },
+ enhanceTitle: async function (event, data) {
+ const node = data.node;
+ const $span = $(node.span);
+
+ if (node.data.noteId !== 'root'
+ && node.data.noteId === hoistedNoteService.getHoistedNoteId()
+ && $span.find('.unhoist-button').length === 0) {
+
+ const unhoistButton = $('<span>&nbsp; (<a class="unhoist-button">unhoist</a>)</span>');
+
+ $span.append(unhoistButton);
+ }
+
+ const note = await treeCache.getNote(node.data.noteId);
+
+ if (note.type === 'search' && $span.find('.refresh-search-button').length === 0) {
+ const refreshSearchButton = $('<span>&nbsp; <span class="refresh-search-button bx bx-refresh" title="Refresh saved search results"></span></span>');
+
+ $span.append(refreshSearchButton);
+ }
+ },
// this is done to automatically lazy load all expanded notes after tree load
loadChildren: (event, data) => {
data.node.visit((subNode) => {
@@ -490,6 +489,20 @@ export default class NoteTreeWidget extends TabAwareWidget {
}
});
+ if (!utils.isMobile()) {
+ this.getHotKeys().then(hotKeys => {
+ for (const key in hotKeys) {
+ const handler = hotKeys[key];
+
+ $(this.tree.$container).on('keydown', null, key, evt => {
+ const node = this.tree.getActiveNode();
+ return handler(node, evt);
+ // return false from the handler will stop default handling.
+ });
+ }
+ });
+ }
+
this.$tree.on('contextmenu', '.fancytree-node', e => {
const node = $.ui.fancytree.getNode(e);
@@ -611,9 +624,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
const note = branch.getNoteFromCache();
if (!note) {
- console.log("branch", branch);
-
- throw new Error(`Branch has no note "${branch.noteId}": ${JSON.stringify(note)}`);
+ throw new Error(`Branch has no note "${branch.noteId}": ${JSON.stringify(branch)}`);
}
const title = (branch.prefix ? (branch.prefix + " - ") : "") + note.title;
@@ -633,11 +644,11 @@ export default class NoteTreeWidget extends TabAwareWidget {
refKey: note.noteId,
lazy: true,
folder: isFolder,
- expanded: branch.isExpanded || hoistedNoteId === note.noteId,
+ expanded: (branch.isExpanded || hoistedNoteId === note.noteId) && note.type !== 'search',
key: utils.randomString(12) // this should prevent some "duplicate key" errors
};
- if (node.folder && node.expanded) {
+ if (isFolder && node.expanded) {
node.children = this.prepareChildren(note);
}
@@ -645,14 +656,8 @@ export default class NoteTreeWidget extends TabAwareWidget {
}
isFolder(note) {
- if (note.type === 'search') {
- return true;
- }
- else {
- const childBranches = this.getChildBranches(note);
-
- return childBranches.length > 0;
- }
+ return note.type === 'search'
+ || this.getChildBranches(note).length > 0;
}
getChildBranches(parentNote) {
diff --git a/src/views/desktop.ejs b/src/views/desktop.ejs
index 4422e26703..ef399712fa 100644
--- a/src/views/desktop.ejs
+++ b/src/views/desktop.ejs
@@ -70,7 +70,6 @@
<script src="libraries/fancytree/jquery.fancytree-all-deps.min.js"></script>
<script src="libraries/jquery.hotkeys.js"></script>
-<script src="libraries/jquery.fancytree.hotkeys.js"></script>
<script src="libraries/autocomplete.jquery.min.js"></script>
diff --git a/src/views/mobile.ejs b/src/views/mobile.ejs
index 2d10baac3a..dc8988871f 100644
--- a/src/views/mobile.ejs
+++ b/src/views/mobile.ejs
@@ -97,10 +97,6 @@
<body class="mobile">
<noscript>Trilium requires JavaScript to be enabled.</noscript>
-<div style="text-align: center" id="loading-indicator">
- <div class="lds-roller"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>
-</div>
-
<div id="toast-container" class="d-flex flex-column justify-content-center align-items-center"></div>
<div class="dropdown-menu dropdown-menu-sm" id="context-menu-container"></div>