From 9c318c95260bff6c76f296cc87b33271f1848f61 Mon Sep 17 00:00:00 2001 From: icarus Date: Tue, 14 Oct 2025 16:10:07 +0800 Subject: [PATCH] fix(SelectionToolbar): avoid earlier access --- .../selection/toolbar/SelectionToolbar.tsx | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/renderer/src/windows/selection/toolbar/SelectionToolbar.tsx b/src/renderer/src/windows/selection/toolbar/SelectionToolbar.tsx index 2d00b127b0..52c97ebf58 100644 --- a/src/renderer/src/windows/selection/toolbar/SelectionToolbar.tsx +++ b/src/renderer/src/windows/selection/toolbar/SelectionToolbar.tsx @@ -204,31 +204,6 @@ const SelectionToolbar: FC<{ demo?: boolean }> = ({ demo = false }) => { } }, [setTimeoutTimer]) - const handleAction = useCallback( - (action: ActionItem) => { - if (demo) return - - /** avoid mutating the original action, it will cause syncing issue */ - const newAction = { ...action, selectedText: selectedText.current } - - switch (action.id) { - case 'copy': - handleCopy() - break - case 'search': - handleSearch(newAction) - break - case 'quote': - handleQuote(newAction) - break - default: - handleDefaultAction(newAction) - break - } - }, - [demo, handleCopy] - ) - const handleSearch = (action: ActionItem) => { if (!action.searchEngine) return @@ -256,6 +231,31 @@ const SelectionToolbar: FC<{ demo?: boolean }> = ({ demo = false }) => { window.api?.selection.hideToolbar() } + const handleAction = useCallback( + (action: ActionItem) => { + if (demo) return + + /** avoid mutating the original action, it will cause syncing issue */ + const newAction = { ...action, selectedText: selectedText.current } + + switch (action.id) { + case 'copy': + handleCopy() + break + case 'search': + handleSearch(newAction) + break + case 'quote': + handleQuote(newAction) + break + default: + handleDefaultAction(newAction) + break + } + }, + [demo, handleCopy] + ) + return (