清理ESC功能

This commit is contained in:
qiuchengw
2025-12-03 09:28:43 +08:00
parent 6cd243e1fd
commit 124ef6e60e
+1 -14
View File
@@ -688,9 +688,6 @@ const handleLinkDragStart = (event: { task: Task; type: 'predecessor' | 'success
// 启动自动滚动检测 // 启动自动滚动检测
startLinkAutoScroll() startLinkAutoScroll()
// 添加 ESC 键监听,允许取消拖拽
document.addEventListener('keydown', handleLinkDragEscape)
// 在 Timeline 层级添加全局鼠标监听器(防止 LinkAnchor 因虚拟滚动卸载导致拖拽中断) // 在 Timeline 层级添加全局鼠标监听器(防止 LinkAnchor 因虚拟滚动卸载导致拖拽中断)
document.addEventListener('mousemove', handleGlobalMouseMove) document.addEventListener('mousemove', handleGlobalMouseMove)
document.addEventListener('mouseup', handleGlobalMouseUp) document.addEventListener('mouseup', handleGlobalMouseUp)
@@ -795,14 +792,6 @@ const handleGlobalMouseUp = () => {
} }
} }
// 处理 ESC 键取消拖拽
const handleLinkDragEscape = (e: KeyboardEvent) => {
if (e.key === 'Escape' && dragLinkMode.value) {
cleanupLinkDrag()
document.removeEventListener('keydown', handleLinkDragEscape)
}
}
// 缓存 bodyContent 的位置信息(避免频繁调用 getBoundingClientRect // 缓存 bodyContent 的位置信息(避免频繁调用 getBoundingClientRect
let cachedBodyRect: DOMRect | null = null let cachedBodyRect: DOMRect | null = null
let bodyRectCacheTime = 0 let bodyRectCacheTime = 0
@@ -854,8 +843,7 @@ const handleLinkDragEnd = (event: { task: Task; type: 'predecessor' | 'successor
// 清除缓存的 rect // 清除缓存的 rect
cachedBodyRect = null cachedBodyRect = null
// 移除 ESC 键监听 // 移除全局鼠标监听
document.removeEventListener('keydown', handleLinkDragEscape) // 移除全局鼠标监听器
document.removeEventListener('mousemove', handleGlobalMouseMove) document.removeEventListener('mousemove', handleGlobalMouseMove)
document.removeEventListener('mouseup', handleGlobalMouseUp) document.removeEventListener('mouseup', handleGlobalMouseUp)
@@ -1176,7 +1164,6 @@ const cleanupLinkDrag = () => {
linkDragGuideRef.value?.clear() linkDragGuideRef.value?.clear()
// 移除全局监听器 // 移除全局监听器
document.removeEventListener('keydown', handleLinkDragEscape)
document.removeEventListener('mousemove', handleGlobalMouseMove) document.removeEventListener('mousemove', handleGlobalMouseMove)
document.removeEventListener('mouseup', handleGlobalMouseUp) document.removeEventListener('mouseup', handleGlobalMouseUp)