mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	note can be activated through 'keyboardShortcut' label
This commit is contained in:
		| @@ -1,5 +1,6 @@ | |||||||
| import server from "./server.js"; | import server from "./server.js"; | ||||||
| import utils from "./utils.js"; | import utils from "./utils.js"; | ||||||
|  | import tree from "./tree.js"; | ||||||
|  |  | ||||||
| class KeyboardAction { | class KeyboardAction { | ||||||
| 	constructor(params) { | 	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) { | function setGlobalActionHandler(actionName, handler) { | ||||||
| 	keyboardActionsLoaded.then(() => { | 	keyboardActionsLoaded.then(() => { | ||||||
| 		const action = keyboardActionRepo[actionName]; | 		const action = keyboardActionRepo[actionName]; | ||||||
|   | |||||||
| @@ -1,11 +1,22 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| const keyboardActions = require('../../services/keyboard_actions'); | const keyboardActions = require('../../services/keyboard_actions'); | ||||||
|  | const sql = require('../../services/sql'); | ||||||
|  |  | ||||||
| async function getKeyboardActions() { | async function getKeyboardActions() { | ||||||
|     return await keyboardActions.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 = { | module.exports = { | ||||||
|     getKeyboardActions |     getKeyboardActions, | ||||||
|  |     getShortcutsForNotes | ||||||
| }; | }; | ||||||
| @@ -246,6 +246,7 @@ function register(app) { | |||||||
|     apiRoute(GET, '/api/similar-notes/:noteId', similarNotesRoute.getSimilarNotes); |     apiRoute(GET, '/api/similar-notes/:noteId', similarNotesRoute.getSimilarNotes); | ||||||
|  |  | ||||||
|     apiRoute(GET, '/api/keyboard-actions', keysRoute.getKeyboardActions); |     apiRoute(GET, '/api/keyboard-actions', keysRoute.getKeyboardActions); | ||||||
|  |     apiRoute(GET, '/api/keyboard-shortcuts-for-notes', keysRoute.getShortcutsForNotes); | ||||||
|  |  | ||||||
|     app.use('', router); |     app.use('', router); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -21,6 +21,7 @@ const BUILTIN_ATTRIBUTES = [ | |||||||
|     { type: 'label', name: 'readOnly' }, |     { type: 'label', name: 'readOnly' }, | ||||||
|     { type: 'label', name: 'cssClass' }, |     { type: 'label', name: 'cssClass' }, | ||||||
|     { type: 'label', name: 'iconClass' }, |     { type: 'label', name: 'iconClass' }, | ||||||
|  |     { type: 'label', name: 'keyboardShortcut' }, | ||||||
|     { type: 'label', name: 'run', isDangerous: true }, |     { type: 'label', name: 'run', isDangerous: true }, | ||||||
|     { type: 'label', name: 'customRequestHandler', isDangerous: true }, |     { type: 'label', name: 'customRequestHandler', isDangerous: true }, | ||||||
|     { type: 'label', name: 'customResourceProvider', isDangerous: true }, |     { type: 'label', name: 'customResourceProvider', isDangerous: true }, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user