mirror of
https://github.com/stablyai/orca.git
synced 2026-10-08 16:02:37 +00:00
fix: guard source control copy feedback (#3513)
This commit is contained in:
@@ -1030,17 +1030,30 @@ function SourceControlInner(): React.JSX.Element {
|
||||
const [pendingDiffCommentsClear, setPendingDiffCommentsClear] =
|
||||
useState<PendingDiffCommentsClear | null>(null)
|
||||
const [isClearingDiffComments, setIsClearingDiffComments] = useState(false)
|
||||
// Why: clipboard IPC can resolve after Source Control unmounts; skip copied
|
||||
// feedback instead of starting a reset timer on a stale panel.
|
||||
const diffCommentsCopyMountedRef = useRef(false)
|
||||
|
||||
useEffect(() => {
|
||||
return () => cancelSourceControlEditorRevealFrames(pendingCommentEditorRevealFrameIdsRef)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
diffCommentsCopyMountedRef.current = true
|
||||
return () => {
|
||||
diffCommentsCopyMountedRef.current = false
|
||||
}
|
||||
}, [])
|
||||
|
||||
const handleCopyDiffComments = useCallback(async (): Promise<void> => {
|
||||
if (diffCommentsForActive.length === 0) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await window.api.ui.writeClipboardText(diffCommentsPrompt)
|
||||
if (!diffCommentsCopyMountedRef.current) {
|
||||
return
|
||||
}
|
||||
setDiffCommentsCopied(true)
|
||||
} catch {
|
||||
// Why: swallow — clipboard write can fail when the window isn't focused.
|
||||
@@ -5843,6 +5856,16 @@ function DiffCommentsInlineList({
|
||||
}, [comments])
|
||||
|
||||
const [copiedId, setCopiedId] = useState<string | null>(null)
|
||||
// Why: clipboard IPC can resolve after the inline notes list unmounts; skip
|
||||
// copied feedback instead of starting a reset timer on a stale list.
|
||||
const copiedIdMountedRef = useRef(false)
|
||||
|
||||
useEffect(() => {
|
||||
copiedIdMountedRef.current = true
|
||||
return () => {
|
||||
copiedIdMountedRef.current = false
|
||||
}
|
||||
}, [])
|
||||
|
||||
// Why: auto-dismiss the per-row "copied" indicator so the button returns to
|
||||
// its default icon after a brief confirmation window. Matches the top-level
|
||||
@@ -5858,6 +5881,9 @@ function DiffCommentsInlineList({
|
||||
const handleCopyOne = useCallback(async (c: DiffComment): Promise<void> => {
|
||||
try {
|
||||
await window.api.ui.writeClipboardText(formatDiffComment(c))
|
||||
if (!copiedIdMountedRef.current) {
|
||||
return
|
||||
}
|
||||
setCopiedId(c.id)
|
||||
} catch {
|
||||
// Why: swallow — clipboard write can fail when the window isn't focused.
|
||||
|
||||
Reference in New Issue
Block a user