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.
This commit is contained in:
fullex 2025-06-11 18:30:48 +08:00 committed by GitHub
parent 8a23c0378d
commit 1f2c467fd4
2 changed files with 6 additions and 4 deletions

View File

@ -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)
}
/**

View File

@ -22,11 +22,12 @@ const ShortcutSettings: FC = () => {
const inputRefs = useRef<Record<string, InputRef>>({})
const [editingKey, setEditingKey] = useState<string | null>(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) => {