mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-01 06:22:44 -08:00
refactor: extract shortcut config resolution utility
This commit is contained in:
82
src/core/utils/shortcut-config.ts
Normal file
82
src/core/utils/shortcut-config.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { Config } from "../../types";
|
||||
|
||||
export interface ConfiguredShortcuts {
|
||||
toggleVisibleOverlayGlobal: string | null | undefined;
|
||||
toggleInvisibleOverlayGlobal: string | null | undefined;
|
||||
copySubtitle: string | null | undefined;
|
||||
copySubtitleMultiple: string | null | undefined;
|
||||
updateLastCardFromClipboard: string | null | undefined;
|
||||
triggerFieldGrouping: string | null | undefined;
|
||||
triggerSubsync: string | null | undefined;
|
||||
mineSentence: string | null | undefined;
|
||||
mineSentenceMultiple: string | null | undefined;
|
||||
multiCopyTimeoutMs: number;
|
||||
toggleSecondarySub: string | null | undefined;
|
||||
markAudioCard: string | null | undefined;
|
||||
openRuntimeOptions: string | null | undefined;
|
||||
}
|
||||
|
||||
export function resolveConfiguredShortcuts(
|
||||
config: Config,
|
||||
defaultConfig: Config,
|
||||
): ConfiguredShortcuts {
|
||||
const normalizeShortcut = (
|
||||
value: string | null | undefined,
|
||||
): string | null | undefined => {
|
||||
if (typeof value !== "string") return value;
|
||||
return value
|
||||
.replace(/\bKey([A-Z])\b/g, "$1")
|
||||
.replace(/\bDigit([0-9])\b/g, "$1");
|
||||
};
|
||||
|
||||
return {
|
||||
toggleVisibleOverlayGlobal: normalizeShortcut(
|
||||
config.shortcuts?.toggleVisibleOverlayGlobal ??
|
||||
defaultConfig.shortcuts?.toggleVisibleOverlayGlobal,
|
||||
),
|
||||
toggleInvisibleOverlayGlobal: normalizeShortcut(
|
||||
config.shortcuts?.toggleInvisibleOverlayGlobal ??
|
||||
defaultConfig.shortcuts?.toggleInvisibleOverlayGlobal,
|
||||
),
|
||||
copySubtitle: normalizeShortcut(
|
||||
config.shortcuts?.copySubtitle ?? defaultConfig.shortcuts?.copySubtitle,
|
||||
),
|
||||
copySubtitleMultiple: normalizeShortcut(
|
||||
config.shortcuts?.copySubtitleMultiple ??
|
||||
defaultConfig.shortcuts?.copySubtitleMultiple,
|
||||
),
|
||||
updateLastCardFromClipboard: normalizeShortcut(
|
||||
config.shortcuts?.updateLastCardFromClipboard ??
|
||||
defaultConfig.shortcuts?.updateLastCardFromClipboard,
|
||||
),
|
||||
triggerFieldGrouping: normalizeShortcut(
|
||||
config.shortcuts?.triggerFieldGrouping ??
|
||||
defaultConfig.shortcuts?.triggerFieldGrouping,
|
||||
),
|
||||
triggerSubsync: normalizeShortcut(
|
||||
config.shortcuts?.triggerSubsync ?? defaultConfig.shortcuts?.triggerSubsync,
|
||||
),
|
||||
mineSentence: normalizeShortcut(
|
||||
config.shortcuts?.mineSentence ?? defaultConfig.shortcuts?.mineSentence,
|
||||
),
|
||||
mineSentenceMultiple: normalizeShortcut(
|
||||
config.shortcuts?.mineSentenceMultiple ??
|
||||
defaultConfig.shortcuts?.mineSentenceMultiple,
|
||||
),
|
||||
multiCopyTimeoutMs:
|
||||
config.shortcuts?.multiCopyTimeoutMs ??
|
||||
defaultConfig.shortcuts?.multiCopyTimeoutMs ??
|
||||
5000,
|
||||
toggleSecondarySub: normalizeShortcut(
|
||||
config.shortcuts?.toggleSecondarySub ??
|
||||
defaultConfig.shortcuts?.toggleSecondarySub,
|
||||
),
|
||||
markAudioCard: normalizeShortcut(
|
||||
config.shortcuts?.markAudioCard ?? defaultConfig.shortcuts?.markAudioCard,
|
||||
),
|
||||
openRuntimeOptions: normalizeShortcut(
|
||||
config.shortcuts?.openRuntimeOptions ??
|
||||
defaultConfig.shortcuts?.openRuntimeOptions,
|
||||
),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user