fix: zoom-aware drag positioning + Text node safety in windowDrag
_startDrag(): divide getBoundingClientRect().left/.top by zoom factor (right/left dock paths too). Also guard e.target.closest() calls against Text nodes that lack the method — prevents close/minimize buttons from failing the skipSelector check and triggering a drag on click.
This commit is contained in:
parent
2e06a82cc1
commit
e19f03fb5d
1 changed files with 8 additions and 5 deletions
|
|
@ -157,11 +157,12 @@ export function makeWindowDraggable(modal, options = {}) {
|
||||||
.forEach(a => a.cancel());
|
.forEach(a => a.cancel());
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
const rect = content.getBoundingClientRect();
|
const rect = content.getBoundingClientRect();
|
||||||
|
const z = parseFloat(getComputedStyle(document.documentElement).zoom) || 1;
|
||||||
if (onDragStart) {
|
if (onDragStart) {
|
||||||
try { onDragStart({ rect, cx, cy }); } catch (_) {}
|
try { onDragStart({ rect, cx, cy }); } catch (_) {}
|
||||||
}
|
}
|
||||||
startX = cx; startY = cy;
|
startX = cx; startY = cy;
|
||||||
startLeft = rect.left; startTop = rect.top;
|
startLeft = rect.left / z; startTop = rect.top / z;
|
||||||
// Pin position so the drag follows the cursor instead of fighting a
|
// Pin position so the drag follows the cursor instead of fighting a
|
||||||
// centering transform / margin. Inline styles win unless CSS uses
|
// centering transform / margin. Inline styles win unless CSS uses
|
||||||
// !important (the fullscreen rules do, by design).
|
// !important (the fullscreen rules do, by design).
|
||||||
|
|
@ -214,16 +215,18 @@ export function makeWindowDraggable(modal, options = {}) {
|
||||||
if (rightDock && modal && modal.classList.contains('modal-right-docked')) {
|
if (rightDock && modal && modal.classList.contains('modal-right-docked')) {
|
||||||
if (rightDock.onMove(cx, cy)) {
|
if (rightDock.onMove(cx, cy)) {
|
||||||
const r = content.getBoundingClientRect();
|
const r = content.getBoundingClientRect();
|
||||||
|
const z2 = parseFloat(getComputedStyle(document.documentElement).zoom) || 1;
|
||||||
startX = cx; startY = cy;
|
startX = cx; startY = cy;
|
||||||
startLeft = r.left; startTop = r.top;
|
startLeft = r.left / z2; startTop = r.top / z2;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (leftDock && modal && modal.classList.contains('modal-left-docked')) {
|
if (leftDock && modal && modal.classList.contains('modal-left-docked')) {
|
||||||
if (leftDock.onMove(cx, cy)) {
|
if (leftDock.onMove(cx, cy)) {
|
||||||
const r = content.getBoundingClientRect();
|
const r = content.getBoundingClientRect();
|
||||||
|
const z3 = parseFloat(getComputedStyle(document.documentElement).zoom) || 1;
|
||||||
startX = cx; startY = cy;
|
startX = cx; startY = cy;
|
||||||
startLeft = r.left; startTop = r.top;
|
startLeft = r.left / z3; startTop = r.top / z3;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -280,7 +283,7 @@ export function makeWindowDraggable(modal, options = {}) {
|
||||||
|
|
||||||
header.addEventListener('mousedown', (e) => {
|
header.addEventListener('mousedown', (e) => {
|
||||||
if (mobileSkip > 0 && window.innerWidth <= mobileSkip) return;
|
if (mobileSkip > 0 && window.innerWidth <= mobileSkip) return;
|
||||||
if (skipSelector && e.target.closest(skipSelector)) return;
|
if (skipSelector && e.target.closest && e.target.closest(skipSelector)) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
movedDuringDrag = false;
|
movedDuringDrag = false;
|
||||||
_startDrag(e.clientX, e.clientY);
|
_startDrag(e.clientX, e.clientY);
|
||||||
|
|
@ -309,7 +312,7 @@ export function makeWindowDraggable(modal, options = {}) {
|
||||||
if (enableTouch) {
|
if (enableTouch) {
|
||||||
header.addEventListener('touchstart', (e) => {
|
header.addEventListener('touchstart', (e) => {
|
||||||
if (mobileSkip > 0 && window.innerWidth <= mobileSkip) return;
|
if (mobileSkip > 0 && window.innerWidth <= mobileSkip) return;
|
||||||
if (skipSelector && e.target.closest(skipSelector)) return;
|
if (skipSelector && e.target.closest && e.target.closest(skipSelector)) return;
|
||||||
const t = e.touches[0];
|
const t = e.touches[0];
|
||||||
if (!t) return;
|
if (!t) return;
|
||||||
movedDuringDrag = false;
|
movedDuringDrag = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue