Compare commits

...
Author SHA1 Message Date
l0ng-ai 1fd65bd01a Merge remote-tracking branch 'origin/main' into fix/tree-drag-hscroll
# Conflicts:
#	src/features/project-tree/ProjectView.test.tsx
2026-11-20 22:12:31 +08:00
l0ng-ai 2cb6322172 fix(project-view): keep the tree from scrolling sideways while dragging
WebKit autoscrolls the pressed tree toward a pointer that moves right of it, so
dragging a file to the editor, terminal or out of the window scrolled long rows
out of view. The drag now holds the horizontal scroll position, as it already
held the vertical one outside the tree.
2026-11-20 22:11:47 +08:00
2 changed files with 20 additions and 1 deletions

No files matched your search

@@ -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"));
+4 -1
View File
@@ -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<HTMLElement>('[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;