From 1f2c467fd4041cf3513c8aa429a1c48a59ff2b8b Mon Sep 17 00:00:00 2001 From: fullex <106392080+0xfullex@users.noreply.github.com> Date: Wed, 11 Jun 2025 18:30:48 +0800 Subject: [PATCH] fix(SelectionAssistant): shortcut in mac and running handling (#7084) fix(SelectionService): enhance selection and clipboard handling - Updated processSelectTextByShortcut to include a check for the 'started' state before processing. - Modified writeToClipboard to ensure it only attempts to write if the selectionHook is available and 'started'. - Adjusted ShortcutSettings to filter out additional shortcuts when not on Windows, improving platform compatibility. --- src/main/services/SelectionService.ts | 5 +++-- src/renderer/src/pages/settings/ShortcutSettings.tsx | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/services/SelectionService.ts b/src/main/services/SelectionService.ts index 0719c2b26b..89082ca68f 100644 --- a/src/main/services/SelectionService.ts +++ b/src/main/services/SelectionService.ts @@ -591,7 +591,7 @@ export class SelectionService { * it's a public method used by shortcut service */ public processSelectTextByShortcut(): void { - if (!this.selectionHook || this.triggerMode !== TriggerMode.Shortcut) return + if (!this.selectionHook || !this.started || this.triggerMode !== TriggerMode.Shortcut) return const selectionData = this.selectionHook.getCurrentSelection() @@ -1189,7 +1189,8 @@ export class SelectionService { } public writeToClipboard(text: string): boolean { - return this.selectionHook?.writeToClipboard(text) ?? false + if (!this.selectionHook || !this.started) return false + return this.selectionHook.writeToClipboard(text) } /** diff --git a/src/renderer/src/pages/settings/ShortcutSettings.tsx b/src/renderer/src/pages/settings/ShortcutSettings.tsx index 4d4cb3321f..a414dd2212 100644 --- a/src/renderer/src/pages/settings/ShortcutSettings.tsx +++ b/src/renderer/src/pages/settings/ShortcutSettings.tsx @@ -22,11 +22,12 @@ const ShortcutSettings: FC = () => { const inputRefs = useRef>({}) const [editingKey, setEditingKey] = useState(null) - //TODO: if shortcut is not available on all the platforms, block the shortcut here + //if shortcut is not available on all the platforms, block the shortcut here let shortcuts = originalShortcuts if (!isWindows) { //Selection Assistant only available on Windows now - shortcuts = shortcuts.filter((s) => s.key !== 'selection_assistant_toggle') + const excludedShortcuts = ['selection_assistant_toggle', 'selection_assistant_select_text'] + shortcuts = shortcuts.filter((s) => !excludedShortcuts.includes(s.key)) } const handleClear = (record: Shortcut) => {