Commit 15c68c46 by pangchong

fix(find-replace): 修正面板定位及拖拽边界限制

- 将查找替换面板定位由绝对定位改为固定定位,提升稳定性
- 拖拽过程中避免重复查询面板元素,优化性能
- 增加拖拽边界限制,保证面板至少保留一定可视区域
- 通过计算移动增量并限制偏移,防止面板超出浏览器视口
- 保持面板在窗口内可见性,提升用户体验
parent 0f788bcf
...@@ -247,11 +247,31 @@ export function useDraggable(visible: Ref<boolean>) { ...@@ -247,11 +247,31 @@ export function useDraggable(visible: Ref<boolean>) {
const initialX = dragOffset.value.x const initialX = dragOffset.value.x
const initialY = dragOffset.value.y const initialY = dragOffset.value.y
// 在拖拽开始时记录面板元素,避免 mousemove 中反复 querySelector
const panelEl = (e.currentTarget as HTMLElement)?.closest('.find-replace-panel') as HTMLElement | null
const onMouseMove = (moveEvt: MouseEvent) => { const onMouseMove = (moveEvt: MouseEvent) => {
if (!dragging.value) return if (!dragging.value) return
dragOffset.value = { const rawX = initialX + moveEvt.clientX - startX
x: initialX + moveEvt.clientX - startX, const rawY = initialY + moveEvt.clientY - startY
y: initialY + moveEvt.clientY - startY
if (panelEl) {
// 以当前 rect 为基准,计算本次移动的 delta 并 clamp
// 保证面板至少有 keepVisible px 留在视口内
const rect = panelEl.getBoundingClientRect()
const vw = window.innerWidth
const vh = window.innerHeight
const keepVisible = 80
const deltaX = rawX - dragOffset.value.x
const deltaY = rawY - dragOffset.value.y
const clampedDeltaX = Math.min(vw - keepVisible - rect.left, Math.max(keepVisible - rect.right, deltaX))
const clampedDeltaY = Math.min(vh - keepVisible - rect.top, Math.max(keepVisible - rect.bottom, deltaY))
dragOffset.value = {
x: dragOffset.value.x + clampedDeltaX,
y: dragOffset.value.y + clampedDeltaY
}
} else {
dragOffset.value = { x: rawX, y: rawY }
} }
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<transition name="slide-fade"> <transition name="slide-fade">
<div <div
v-if="visible" v-if="visible"
class="find-replace-panel absolute top-20 right-4 z-[999] bg-card/90 backdrop-blur-md border border-divider shadow-2xl rounded-xl p-4 flex flex-col space-y-3 select-none" class="find-replace-panel fixed top-20 right-4 z-[999] bg-card/90 backdrop-blur-md border border-divider shadow-2xl rounded-xl p-4 flex flex-col space-y-3 select-none"
:style="{ :style="{
width: computedWidth, width: computedWidth,
height: computedHeight, height: computedHeight,
......
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