From 3bbbefa3db0460140107086e1b20ba61f7998f86 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Fri, 29 May 2026 04:18:27 -0700 Subject: [PATCH] Move editor copy reset timers to handlers --- .../src/components/editor/EditorPanel.tsx | 19 ++++++++++++------- .../src/components/editor/MarkdownPreview.tsx | 16 ++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/renderer/src/components/editor/EditorPanel.tsx b/src/renderer/src/components/editor/EditorPanel.tsx index 63d85e01668..f7c51339cb6 100644 --- a/src/renderer/src/components/editor/EditorPanel.tsx +++ b/src/renderer/src/components/editor/EditorPanel.tsx @@ -50,6 +50,7 @@ function EditorPanelInner({ const [copiedPathToast, setCopiedPathToast] = useState<{ fileId: string; token: number } | null>( null ) + const copiedPathResetTimerRef = useRef(null) const [showMarkdownTableOfContents, setShowMarkdownTableOfContents] = useState(false) const [sideBySide, setSideBySide] = useState(settings?.diffDefaultView === 'side-by-side') const [prevDiffView, setPrevDiffView] = useState(settings?.diffDefaultView) @@ -89,13 +90,6 @@ function EditorPanelInner({ useEffect(() => acquireExportPdfListener(), []) useClosedEditorTabCleanup(openFiles) useMarkdownPreviewShortcut({ activeFile, panelRef, openMarkdownPreview }) - useEffect(() => { - if (!copiedPathToast) { - return - } - const timeout = window.setTimeout(() => setCopiedPathToast(null), 1500) - return () => window.clearTimeout(timeout) - }, [copiedPathToast]) const handleContentChangeForFile = useCallback( (file: typeof activeFile, content: string) => { @@ -181,8 +175,19 @@ function EditorPanelInner({ } try { await window.api.ui.writeClipboardText(copyState.copyText) + if (copiedPathResetTimerRef.current !== null) { + window.clearTimeout(copiedPathResetTimerRef.current) + } setCopiedPathToast({ fileId: activeFile.id, token: Date.now() }) + copiedPathResetTimerRef.current = window.setTimeout(() => { + setCopiedPathToast(null) + copiedPathResetTimerRef.current = null + }, 1500) } catch { + if (copiedPathResetTimerRef.current !== null) { + window.clearTimeout(copiedPathResetTimerRef.current) + copiedPathResetTimerRef.current = null + } setCopiedPathToast(null) } }, [activeFile]) diff --git a/src/renderer/src/components/editor/MarkdownPreview.tsx b/src/renderer/src/components/editor/MarkdownPreview.tsx index fc807fe51ee..531fd53e769 100644 --- a/src/renderer/src/components/editor/MarkdownPreview.tsx +++ b/src/renderer/src/components/editor/MarkdownPreview.tsx @@ -459,6 +459,7 @@ export default function MarkdownPreview({ const [activeAnnotationBlockKey, setActiveAnnotationBlockKey] = useState(null) const [reviewPanelOpen, setReviewPanelOpen] = useState(false) const [reviewNotesCopied, setReviewNotesCopied] = useState(false) + const reviewNotesCopiedResetTimerRef = useRef(null) const [activeReviewCommentId, setActiveReviewCommentId] = useState(null) const markdownReviewNotes = useMemo( () => sortMarkdownReviewNotes(markdownComments as MarkdownReviewNote[]), @@ -716,20 +717,19 @@ export default function MarkdownPreview({ } try { await window.api.ui.writeClipboardText(markdownReviewPrompt) + if (reviewNotesCopiedResetTimerRef.current !== null) { + window.clearTimeout(reviewNotesCopiedResetTimerRef.current) + } setReviewNotesCopied(true) + reviewNotesCopiedResetTimerRef.current = window.setTimeout(() => { + setReviewNotesCopied(false) + reviewNotesCopiedResetTimerRef.current = null + }, 1600) } catch { // Best-effort clipboard action; failures usually mean the window is not focused. } }, [markdownReviewNotes.length, markdownReviewPrompt]) - useEffect(() => { - if (!reviewNotesCopied) { - return - } - const timeout = window.setTimeout(() => setReviewNotesCopied(false), 1600) - return () => window.clearTimeout(timeout) - }, [reviewNotesCopied]) - const scrollToReviewNote = useCallback((comment: DiffComment): void => { setActiveReviewCommentId(comment.id) const root = rootRef.current