Prevent manual copy dialog event bleed

This commit is contained in:
FengLee
2026-05-13 17:11:48 +08:00
parent d5972ad14e
commit baa7bbc79b

View File

@@ -22,6 +22,7 @@ function openManualCopyDialog(value: string): ClipboardCopyResult {
overlay.style.padding = '24px';
overlay.style.background = 'rgba(16, 12, 8, 0.52)';
overlay.style.backdropFilter = 'blur(8px)';
overlay.style.pointerEvents = 'auto';
const panel = document.createElement('div');
panel.style.width = 'min(720px, 100%)';
@@ -62,6 +63,8 @@ function openManualCopyDialog(value: string): ClipboardCopyResult {
textarea.style.fontSize = '13px';
textarea.style.lineHeight = '1.65';
textarea.style.outline = 'none';
textarea.style.userSelect = 'text';
textarea.style.webkitUserSelect = 'text';
const actions = document.createElement('div');
actions.style.display = 'flex';
@@ -79,8 +82,30 @@ function openManualCopyDialog(value: string): ClipboardCopyResult {
closeButton.style.color = '#24170f';
closeButton.style.cursor = 'pointer';
const stopDialogEvent = (event: Event) => {
event.stopPropagation();
if (typeof event.stopImmediatePropagation === 'function') {
event.stopImmediatePropagation();
}
};
const stopOverlayDoubleClick = (event: Event) => {
stopDialogEvent(event);
if (event.target === overlay) event.preventDefault();
};
const guardedEvents = ['pointerdown', 'pointerup', 'mousedown', 'mouseup', 'click', 'dblclick', 'touchstart', 'touchend'] as const;
guardedEvents.forEach(eventName => {
overlay.addEventListener(eventName, eventName === 'dblclick' ? stopOverlayDoubleClick : stopDialogEvent, true);
});
textarea.addEventListener('dblclick', stopDialogEvent, true);
panel.addEventListener('dblclick', stopDialogEvent, true);
const close = () => {
window.removeEventListener('keydown', handleKeyDown, true);
guardedEvents.forEach(eventName => {
overlay.removeEventListener(eventName, eventName === 'dblclick' ? stopOverlayDoubleClick : stopDialogEvent, true);
});
textarea.removeEventListener('dblclick', stopDialogEvent, true);
panel.removeEventListener('dblclick', stopDialogEvent, true);
overlay.remove();
};
const handleKeyDown = (event: KeyboardEvent) => {