fix(ui): start pointer drags only while the primary button is held (#1071)

On macOS, with an editable element focused and an input method active, WebKit can deliver a tap as pointerup then pointerdown, so drag trackers saw every later pointermove as a held button: one tap plus a pointer move started a phantom drag (file drag label, tab detach, tool window move) and the next tap dropped it. A drag now starts only from a move with the primary button down, a move without it cancels the press, and late button-less moves after a drag started are ignored so the drop is kept. Resizers, dialog drag/resize, pan and the review gutter end instead; the Project view also listens for pointercancel.

Refs #760

Co-authored-by: ntbang0901 <[email protected]>
Цей коміт міститься в:
ntbang0901 authored and GitHub committed 2026-11-04 01:31:10 +08:00
1 джерело a35e434376
коміт 555226a9bf
15 files changed
+180 -9

No files matched your search

+5
Переглянути файл
@@ -146,6 +146,9 @@ export function startPointerDrag(
const session = dragSession(data);
const onMove = (ev: PointerEvent) => {
if (!ghost) {
// macOS WebKit can deliver a tap's pointerup before its pointerdown, so a
// press with no button held would otherwise start a phantom drag.
if (!(ev.buttons & 1)) return onCancel();
if (Math.hypot(ev.clientX - start.x, ev.clientY - start.y) < DRAG_THRESHOLD) return;
const r = source.getBoundingClientRect();
ghost = source.cloneNode(true) as HTMLElement;
@@ -165,6 +168,8 @@ export function startPointerDrag(
document.documentElement.classList.add(styles.dragging!);
opts.onStart?.();
}
// Late moves after release may still precede the pointerup; ignore, don't cancel the drop.
if (!(ev.buttons & 1)) return;
ghost.style.transform = `translate(${ev.clientX - start.x}px, ${ev.clientY - start.y}px)`;
ghost.classList.toggle(styles.noTarget!, !session.move(ev.clientX, ev.clientY));
};