Move contextual copy toast cleanup to editor dispose

This commit is contained in:
Neil
2026-05-29 15:55:59 -07:00
parent c7cd858503
commit dd2020a084
2 changed files with 8 additions and 10 deletions
@@ -294,6 +294,13 @@ export function setupContextualCopy({
editorDomNode.addEventListener('mouseup', updateCopyHint, true)
editorDomNode.addEventListener('keyup', updateCopyHint, true)
editorInstance.onDidDispose(() => {
// Why: the confirmation toast timeout belongs to the Monaco editor that
// scheduled it, so editor disposal is the earliest reliable cleanup point.
if (copyToastTimeoutRef.current !== null) {
window.clearTimeout(copyToastTimeoutRef.current)
copyToastTimeoutRef.current = null
setCopyToast(null)
}
if (primarySelectionTimer !== null) {
window.clearTimeout(primarySelectionTimer)
primarySelectionTimer = null
@@ -1,4 +1,4 @@
import React, { useRef, useState, useEffect, useCallback } from 'react'
import React, { useRef, useState, useCallback } from 'react'
import type { editor } from 'monaco-editor'
import { setupContextualCopy } from './setup-contextual-copy'
@@ -6,15 +6,6 @@ export function useContextualCopySetup() {
const [copyToast, setCopyToast] = useState<{ left: number; top: number } | null>(null)
const copyToastTimeoutRef = useRef<number | null>(null)
useEffect(() => {
const toastRef = copyToastTimeoutRef
return () => {
if (toastRef.current !== null) {
window.clearTimeout(toastRef.current)
}
}
}, [])
const setupCopy = useCallback(
(
editorInstance: editor.IStandaloneCodeEditor,