дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 01:31:41 +02:00
fix(ui): keep a file drag from selecting the text it passes over (#3358)
Dragging a file from the Project view selected the editor text the pointer passed over (#3334). WebKit keeps contenteditable text selectable whatever its user-select, and starts a selection there during a mouse drag even when the press selected nothing. beginDrag() now clears the selection and marks every pointer drag (startPointerDrag, the Project view's own file drag, tool window stripe buttons): no selection, and inputs, textareas and contenteditable out of hit testing (drop targets are their containers). Co-authored-by: akshathayadav378-boop <[email protected]>
Цей коміт міститься в:
1 джерело
f795aa3232
коміт
b2c22ccec6
6 files changed
+64
-3
No files matched your search
@@ -115,6 +115,19 @@ export function dragSession(data: DragData): DragSession {
|
||||
/** Movement before a press becomes a drag, px. */
|
||||
const DRAG_THRESHOLD = 4;
|
||||
|
||||
/**
|
||||
* Marks a pointer drag as running until the returned function is called: no text
|
||||
* selection, and editable text out of hit testing. WebKit starts a selection in
|
||||
* editable text the pointer passes over even when the press selected nothing
|
||||
* (#3334), so every pointer-driven drag, built on `startPointerDrag` or not, uses this.
|
||||
*/
|
||||
export function beginDrag(): () => void {
|
||||
window.getSelection()?.removeAllRanges();
|
||||
const html = document.documentElement;
|
||||
html.classList.add(styles.dragging!);
|
||||
return () => html.classList.remove(styles.dragging!);
|
||||
}
|
||||
|
||||
/** Settings › Appearance › "Drag-and-drop with Alt pressed only" for tabs and stripe buttons. */
|
||||
let requiresAlt = () => false;
|
||||
export function setDragRequiresAlt(fn: () => boolean) {
|
||||
@@ -150,6 +163,7 @@ export function startPointerDrag(
|
||||
if (e.button !== 0 || (!opts.always && requiresAlt() && !e.altKey)) return;
|
||||
const start = { x: e.clientX, y: e.clientY };
|
||||
let ghost: HTMLElement | null = null;
|
||||
let endDrag: (() => void) | null = null;
|
||||
const session = dragSession(data);
|
||||
const onMove = (ev: PointerEvent) => {
|
||||
if (!ghost) {
|
||||
@@ -172,7 +186,7 @@ export function startPointerDrag(
|
||||
height: `${r.height}px`,
|
||||
});
|
||||
document.body.appendChild(ghost);
|
||||
document.documentElement.classList.add(styles.dragging!);
|
||||
endDrag = beginDrag();
|
||||
opts.onStart?.();
|
||||
}
|
||||
// Late moves after release may still precede the pointerup; ignore, don't cancel the drop.
|
||||
@@ -204,7 +218,7 @@ export function startPointerDrag(
|
||||
window.removeEventListener("pointercancel", onCancel);
|
||||
window.removeEventListener("keydown", onKey, true);
|
||||
ghost?.remove();
|
||||
document.documentElement.classList.remove(styles.dragging!);
|
||||
endDrag?.();
|
||||
};
|
||||
const onCancel = () => {
|
||||
session.cancel();
|
||||
|
||||
Reference in new issue
Заблокувати користувача