mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	shortcut improvements
This commit is contained in:
		| @@ -509,6 +509,8 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain | |||||||
|      * @method |      * @method | ||||||
|      * @param {string} keyboardShortcut - e.g. "ctrl+shift+a" |      * @param {string} keyboardShortcut - e.g. "ctrl+shift+a" | ||||||
|      * @param {function} handler |      * @param {function} handler | ||||||
|  |      * @param {string} [namespace] - specify namespace of the handler for the cases where call for bind may be repeated. | ||||||
|  |      *                               If a handler with this ID exists, it's replaced by the new handler. | ||||||
|      */ |      */ | ||||||
|     this.bindGlobalShortcut = shortcutService.bindGlobalShortcut; |     this.bindGlobalShortcut = shortcutService.bindGlobalShortcut; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -72,7 +72,7 @@ export default class RootCommandExecutor extends Component { | |||||||
|         options.toggle('leftPaneVisible'); |         options.toggle('leftPaneVisible'); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async showLaunchBarShortcutsCommand() { |     async showLaunchBarSubtreeCommand() { | ||||||
|         await appContext.tabManager.openContextWithNote('lb_root', true, null, 'lb_root'); |         await appContext.tabManager.openContextWithNote('lb_root', true, null, 'lb_root'); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,19 +1,31 @@ | |||||||
| import utils from "./utils.js"; | import utils from "./utils.js"; | ||||||
|  |  | ||||||
| function bindGlobalShortcut(keyboardShortcut, handler) { | function bindGlobalShortcut(keyboardShortcut, handler, namespace = null) { | ||||||
|     bindElShortcut($(document), keyboardShortcut, handler); |     bindElShortcut($(document), keyboardShortcut, handler); | ||||||
| } | } | ||||||
|  |  | ||||||
| function bindElShortcut($el, keyboardShortcut, handler) { | function bindElShortcut($el, keyboardShortcut, handler, namespace = null) { | ||||||
|     if (utils.isDesktop()) { |     if (utils.isDesktop()) { | ||||||
|         keyboardShortcut = normalizeShortcut(keyboardShortcut); |         keyboardShortcut = normalizeShortcut(keyboardShortcut); | ||||||
|  |  | ||||||
|         $el.bind('keydown', keyboardShortcut, e => { |         let eventName = 'keydown'; | ||||||
|             handler(e); |  | ||||||
|  |  | ||||||
|             e.preventDefault(); |         if (namespace) { | ||||||
|             e.stopPropagation(); |             eventName += "." + namespace; | ||||||
|         }); |  | ||||||
|  |             // if there's a namespace then we replace the existing event handler with the new one | ||||||
|  |             $el.off(eventName); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // method can be called to remove the shortcut (e.g. when keyboardShortcut label is deleted) | ||||||
|  |         if (keyboardShortcut) { | ||||||
|  |             $el.on(eventName, keyboardShortcut, e => { | ||||||
|  |                 handler(e); | ||||||
|  |  | ||||||
|  |                 e.preventDefault(); | ||||||
|  |                 e.stopPropagation(); | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -21,6 +33,10 @@ function bindElShortcut($el, keyboardShortcut, handler) { | |||||||
|  * Normalize to the form expected by the jquery.hotkeys.js |  * Normalize to the form expected by the jquery.hotkeys.js | ||||||
|  */ |  */ | ||||||
| function normalizeShortcut(shortcut) { | function normalizeShortcut(shortcut) { | ||||||
|  |     if (!shortcut) { | ||||||
|  |         return shortcut; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     return shortcut |     return shortcut | ||||||
|         .toLowerCase() |         .toLowerCase() | ||||||
|         .replace("enter", "return") |         .replace("enter", "return") | ||||||
|   | |||||||
| @@ -124,9 +124,9 @@ const TPL = ` | |||||||
|             <kbd ></kbd> |             <kbd ></kbd> | ||||||
|         </li> |         </li> | ||||||
|          |          | ||||||
|         <li class="dropdown-item" data-trigger-command="showLaunchBarShortcuts"> |         <li class="dropdown-item" data-trigger-command="showLaunchBarSubtree"> | ||||||
|             <span class="bx bx-sidebar"></span> |             <span class="bx bx-sidebar"></span> | ||||||
|             Configure launchbar shortcuts |             Configure launchbar | ||||||
|         </li> |         </li> | ||||||
|          |          | ||||||
|         <li class="dropdown-item" data-trigger-command="showShareSubtree"> |         <li class="dropdown-item" data-trigger-command="showShareSubtree"> | ||||||
|   | |||||||
| @@ -13,6 +13,13 @@ function getShortcutsForNotes() { | |||||||
|     const map = {}; |     const map = {}; | ||||||
|  |  | ||||||
|     for (const attr of attrs) { |     for (const attr of attrs) { | ||||||
|  |         const note = becca.getNote(attr.noteId); | ||||||
|  |  | ||||||
|  |         if (note?.type === 'launcher') { | ||||||
|  |             // launchers have different handling | ||||||
|  |             continue; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         map[attr.value] = attr.noteId; |         map[attr.value] = attr.noteId; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user