mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	
		
			
	
	
		
			37 lines
		
	
	
		
			885 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
		
		
			
		
	
	
			37 lines
		
	
	
		
			885 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
|  | import utils from "./utils.js"; | ||
|  | 
 | ||
|  | function bindGlobalShortcut(keyboardShortcut, handler) { | ||
|  |     bindElShortcut($(document), keyboardShortcut, handler); | ||
|  | } | ||
|  | 
 | ||
|  | function bindElShortcut($el, keyboardShortcut, handler) { | ||
|  |     if (utils.isDesktop()) { | ||
|  |         keyboardShortcut = normalizeShortcut(keyboardShortcut); | ||
|  | 
 | ||
|  |         $el.bind('keydown', keyboardShortcut, e => { | ||
|  |             handler(e); | ||
|  | 
 | ||
|  |             e.preventDefault(); | ||
|  |             e.stopPropagation(); | ||
|  |         }); | ||
|  |     } | ||
|  | } | ||
|  | 
 | ||
|  | /** | ||
|  |  * Normalize to the form expected by the jquery.hotkeys.js | ||
|  |  */ | ||
|  | function normalizeShortcut(shortcut) { | ||
|  |     return shortcut | ||
|  |         .toLowerCase() | ||
|  |         .replace("enter", "return") | ||
|  |         .replace("delete", "del") | ||
|  |         .replace("ctrl+alt", "alt+ctrl") | ||
|  |         .replace("meta+alt", "alt+meta"); // alt needs to be first;
 | ||
|  | } | ||
|  | 
 | ||
|  | export default { | ||
|  |     bindGlobalShortcut, | ||
|  |     bindElShortcut, | ||
|  |     normalizeShortcut | ||
|  | } |