diff --git a/src/features/project-tree/ProjectView.test.tsx b/src/features/project-tree/ProjectView.test.tsx index f668a1078..de863baeb 100644 --- a/src/features/project-tree/ProjectView.test.tsx +++ b/src/features/project-tree/ProjectView.test.tsx @@ -398,6 +398,22 @@ describe("ProjectView", () => { expect(ghost()).toBeNull(); }); + it("keeps the tree from scrolling sideways during a drag", async () => { + const { tree, row, rows } = setup(); + await waitFor(() => expect(rows()).toContain("README.md")); + document.elementFromPoint = () => null; + fireEvent( + row("README.md").querySelector("[data-project-path]")!, + new MouseEvent("pointerdown", { bubbles: true, button: 0 }), + ); + act(() => void window.dispatchEvent(new MouseEvent("pointermove", { buttons: 1, clientX: 40, clientY: 0 }))); + // WebKit's autoscroll toward a pointer right of the tree. + tree.scrollLeft = 600; + fireEvent.scroll(tree); + expect(tree.scrollLeft).toBe(0); + act(() => void window.dispatchEvent(new MouseEvent("pointerup", { bubbles: true }))); + }); + it("hands the selected files to an OS drag once the pointer leaves the window", async () => { const { row, rows } = setup(); await waitFor(() => expect(rows()).toContain("README.md")); diff --git a/src/features/project-tree/ProjectView.tsx b/src/features/project-tree/ProjectView.tsx index c926f29b9..656b18bd0 100644 --- a/src/features/project-tree/ProjectView.tsx +++ b/src/features/project-tree/ProjectView.tsx @@ -672,9 +672,11 @@ export function ProjectView() { // While dragging, the tree scrolls only when the pointer is near its top or bottom edge // (IDEA's DnD autoscroll). Leaving the tree toward a drop target elsewhere (the terminal, // an editor) keeps it where it is: WebKit's own autoscroll of the pressed scroll container - // would otherwise keep scrolling it toward the pointer. + // would otherwise keep scrolling it toward the pointer. It never scrolls sideways: a pointer + // right of the tree would scroll its long rows out of view. const scroller = containerRef.current?.querySelector('[role="tree"]') ?? null; let held = scroller?.scrollTop ?? 0; + const heldLeft = scroller?.scrollLeft ?? 0; let pointer: { x: number; y: number } | null = null; let frame = 0; const inside = (p: { x: number; y: number }) => { @@ -685,6 +687,7 @@ export function ProjectView() { if (!scroller) return; if (pointer && !inside(pointer)) scroller.scrollTop = held; else held = scroller.scrollTop; + if (scroller.scrollLeft !== heldLeft) scroller.scrollLeft = heldLeft; }; const edgeScroll = () => { frame = 0;