mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-09 09:42:28 +08:00
chore(client/ts): port services/shortcuts
This commit is contained in:
parent
e8d1fe4e84
commit
7b7980cefb
@ -1,14 +1,17 @@
|
|||||||
import utils from "./utils.js";
|
import utils from "./utils.js";
|
||||||
|
|
||||||
function removeGlobalShortcut(namespace) {
|
type ElementType = HTMLElement | Document;
|
||||||
|
type Handler = (e: JQuery.TriggeredEvent<ElementType, string, ElementType, ElementType>) => void;
|
||||||
|
|
||||||
|
function removeGlobalShortcut(namespace: string) {
|
||||||
bindGlobalShortcut('', null, namespace);
|
bindGlobalShortcut('', null, namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
function bindGlobalShortcut(keyboardShortcut, handler, namespace = null) {
|
function bindGlobalShortcut(keyboardShortcut: string, handler: Handler | null, namespace: string | null = null) {
|
||||||
bindElShortcut($(document), keyboardShortcut, handler, namespace);
|
bindElShortcut($(document), keyboardShortcut, handler, namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
function bindElShortcut($el, keyboardShortcut, handler, namespace = null) {
|
function bindElShortcut($el: JQuery<ElementType>, keyboardShortcut: string, handler: Handler | null, namespace: string | null = null) {
|
||||||
if (utils.isDesktop()) {
|
if (utils.isDesktop()) {
|
||||||
keyboardShortcut = normalizeShortcut(keyboardShortcut);
|
keyboardShortcut = normalizeShortcut(keyboardShortcut);
|
||||||
|
|
||||||
@ -24,7 +27,9 @@ function bindElShortcut($el, keyboardShortcut, handler, namespace = null) {
|
|||||||
// method can be called to remove the shortcut (e.g. when keyboardShortcut label is deleted)
|
// method can be called to remove the shortcut (e.g. when keyboardShortcut label is deleted)
|
||||||
if (keyboardShortcut) {
|
if (keyboardShortcut) {
|
||||||
$el.bind(eventName, keyboardShortcut, e => {
|
$el.bind(eventName, keyboardShortcut, e => {
|
||||||
|
if (handler) {
|
||||||
handler(e);
|
handler(e);
|
||||||
|
}
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@ -36,7 +41,7 @@ function bindElShortcut($el, keyboardShortcut, handler, namespace = null) {
|
|||||||
/**
|
/**
|
||||||
* 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: string): string {
|
||||||
if (!shortcut) {
|
if (!shortcut) {
|
||||||
return shortcut;
|
return shortcut;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user