Skip to content

Build your personal knowledge base with Trilium Notes

note can be activated through 'keyboardShortcut' label

zadamcd139bdd767c
diff --git a/src/public/javascripts/services/keyboard_actions.js b/src/public/javascripts/services/keyboard_actions.js
index 1fec0ee98e..43638a7329 100644
--- a/src/public/javascripts/services/keyboard_actions.js
+++ b/src/public/javascripts/services/keyboard_actions.js
@@ -1,5 +1,6 @@
import server from "./server.js";
import utils from "./utils.js";
+import tree from "./tree.js";
class KeyboardAction {
constructor(params) {
@@ -33,6 +34,16 @@ const keyboardActionsLoaded = server.get('keyboard-actions').then(actions => {
}
});
+server.get('keyboard-shortcuts-for-notes').then(shortcutForNotes => {
+ for (const shortcut in shortcutForNotes) {
+ utils.bindGlobalShortcut(shortcut, async () => {
+ const treeService = (await import("./tree.js")).default;
+
+ treeService.activateNote(shortcutForNotes[shortcut]);
+ });
+ }
+});
+
function setGlobalActionHandler(actionName, handler) {
keyboardActionsLoaded.then(() => {
const action = keyboardActionRepo[actionName];
diff --git a/src/routes/api/keys.js b/src/routes/api/keys.js
index 8d81c08426..95fc03e629 100644
--- a/src/routes/api/keys.js
+++ b/src/routes/api/keys.js
@@ -1,11 +1,22 @@
"use strict";
const keyboardActions = require('../../services/keyboard_actions');
+const sql = require('../../services/sql');
async function getKeyboardActions() {
return await keyboardActions.getKeyboardActions();
}
+async function getShortcutsForNotes() {
+ return await sql.getMap(`
+ SELECT value, noteId
+ FROM attributes
+ WHERE isDeleted = 0
+ AND type = 'label'
+ AND name = 'keyboardShortcut'`);
+}
+
module.exports = {
- getKeyboardActions
+ getKeyboardActions,
+ getShortcutsForNotes
};
\ No newline at end of file
diff --git a/src/routes/routes.js b/src/routes/routes.js
index 2e3926678d..725d07ae50 100644
--- a/src/routes/routes.js
+++ b/src/routes/routes.js
@@ -246,6 +246,7 @@ function register(app) {
apiRoute(GET, '/api/similar-notes/:noteId', similarNotesRoute.getSimilarNotes);
apiRoute(GET, '/api/keyboard-actions', keysRoute.getKeyboardActions);
+ apiRoute(GET, '/api/keyboard-shortcuts-for-notes', keysRoute.getShortcutsForNotes);
app.use('', router);
}
diff --git a/src/services/attributes.js b/src/services/attributes.js
index 876ae3c13f..d1abd7cecc 100644
--- a/src/services/attributes.js
+++ b/src/services/attributes.js
@@ -21,6 +21,7 @@ const BUILTIN_ATTRIBUTES = [
{ type: 'label', name: 'readOnly' },
{ type: 'label', name: 'cssClass' },
{ type: 'label', name: 'iconClass' },
+ { type: 'label', name: 'keyboardShortcut' },
{ type: 'label', name: 'run', isDangerous: true },
{ type: 'label', name: 'customRequestHandler', isDangerous: true },
{ type: 'label', name: 'customResourceProvider', isDangerous: true },