Commit ea9823e9 by pangchong

feat: 解决 点击编辑区内容时编辑区自动滚动/定位 的问题

parent 9b585f84
...@@ -389,9 +389,26 @@ export function useEditorPanel() { ...@@ -389,9 +389,26 @@ export function useEditorPanel() {
}) })
} }
const isEditAreaClick = ref(false)
let clickTimer: ReturnType<typeof setTimeout> | null = null
const handleViewportMouseDown = () => {
isEditAreaClick.value = true
if (clickTimer) clearTimeout(clickTimer)
clickTimer = setTimeout(() => {
isEditAreaClick.value = false
}, 200)
}
watch( watch(
() => editorStore.selectedNodeId, () => editorStore.selectedNodeId,
(newId) => syncEditorScroll(newId, true) (newId) => {
if (isEditAreaClick.value) {
isEditAreaClick.value = false
return
}
syncEditorScroll(newId, false)
}
) )
watch( watch(
() => editorStore.lastUndoRedoTime, () => editorStore.lastUndoRedoTime,
...@@ -409,6 +426,8 @@ export function useEditorPanel() { ...@@ -409,6 +426,8 @@ export function useEditorPanel() {
handleScroll, handleScroll,
setBlockRef, setBlockRef,
syncEditorScroll, syncEditorScroll,
scrollTop scrollTop,
handleViewportMouseDown
} }
} }
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
class="flex-1 overflow-y-auto min-h-0 leading-relaxed relative" class="flex-1 overflow-y-auto min-h-0 leading-relaxed relative"
@scroll="handleScroll" @scroll="handleScroll"
@contextmenu="handleContextMenu" @contextmenu="handleContextMenu"
@mousedown="handleViewportMouseDown"
> >
<!-- 占位撑高,模拟全量内容总高度 --> <!-- 占位撑高,模拟全量内容总高度 -->
<div :style="{ height: totalHeight + 'px', position: 'relative' }"> <div :style="{ height: totalHeight + 'px', position: 'relative' }">
...@@ -114,7 +115,8 @@ const { ...@@ -114,7 +115,8 @@ const {
handleScroll, handleScroll,
setBlockRef, setBlockRef,
syncEditorScroll, syncEditorScroll,
scrollTop scrollTop,
handleViewportMouseDown
} = useEditorPanel() } = useEditorPanel()
const findReplaceVisible = ref(false) const findReplaceVisible = ref(false)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment