mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-31 00:22:30 +00:00
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
export interface ShortcutLikeEvent {
|
|
key: string;
|
|
metaKey?: boolean;
|
|
ctrlKey?: boolean;
|
|
altKey?: boolean;
|
|
isComposing?: boolean;
|
|
}
|
|
|
|
export function isExecuteSqlShortcut(event: ShortcutLikeEvent): boolean {
|
|
if (event.isComposing) return false;
|
|
if (event.altKey) return false;
|
|
if (!event.metaKey && !event.ctrlKey) return false;
|
|
return event.key === "Enter";
|
|
}
|
|
|
|
export function isCloseTabShortcut(event: ShortcutLikeEvent): boolean {
|
|
if (event.isComposing) return false;
|
|
if (!event.metaKey) return false;
|
|
return event.key.toLowerCase() === "w";
|
|
}
|
|
|
|
export function isFocusSearchShortcut(event: ShortcutLikeEvent): boolean {
|
|
if (event.isComposing) return false;
|
|
if (event.altKey) return false;
|
|
if (!event.metaKey && !event.ctrlKey) return false;
|
|
return event.key.toLowerCase() === "f";
|
|
}
|
|
|
|
export function isSaveShortcut(event: ShortcutLikeEvent): boolean {
|
|
if (event.isComposing) return false;
|
|
if (event.altKey) return false;
|
|
if (!event.metaKey && !event.ctrlKey) return false;
|
|
return event.key.toLowerCase() === "s";
|
|
}
|
|
|
|
export function isObjectSourceSaveShortcutTarget(
|
|
target: { closest(selector: string): unknown } | null | undefined,
|
|
): boolean {
|
|
return !!target?.closest("[data-object-source-editor], [data-object-source-preview]");
|
|
}
|
|
|
|
export function isCancelSearchShortcut(event: ShortcutLikeEvent): boolean {
|
|
if (event.isComposing) return false;
|
|
return event.key === "Escape";
|
|
}
|