mirror of
https://github.com/stablyai/orca.git
synced 2026-10-16 08:03:09 +00:00
Move contextual copy toast cleanup to editor dispose
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user