fix(web): scrolling over the thread minimap scrolls the chat (#17652)
This commit is contained in:
1 parent
9e8c7206c8
commit
c9181d81a8
3 files changed
+113
No files matched your search
@@ -297,6 +297,7 @@ import { TimelineSystemDivider } from "./TimelineSystemDivider";
|
||||
import { SkillChipIcon, SkillInlineText } from "./SkillInlineText";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import { formatWorkspaceRelativePath } from "../../filePathDisplay";
|
||||
import { forwardWheelToTimeline } from "./timelineMinimapWheel";
|
||||
import {
|
||||
buildReviewCommentRenderablePatch,
|
||||
formatReviewCommentFence,
|
||||
@@ -1571,6 +1572,14 @@ const ConversationTimeline = memo(function ConversationTimeline({
|
||||
[],
|
||||
);
|
||||
|
||||
const forwardMinimapWheel = useCallback(
|
||||
(event: WheelEvent) => {
|
||||
const scrollNode = listRef.current?.getScrollableNode();
|
||||
if (scrollNode) forwardWheelToTimeline(event, scrollNode);
|
||||
},
|
||||
[listRef],
|
||||
);
|
||||
|
||||
if (
|
||||
rows.length === 0 &&
|
||||
!isWorking &&
|
||||
@@ -1661,6 +1670,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
|
||||
hitStripWidth={minimapHitStripWidth}
|
||||
currentIndex={minimapCurrentIndex}
|
||||
stripMap={minimapStripMap}
|
||||
onWheel={forwardMinimapWheel}
|
||||
onSelect={(item) => {
|
||||
onManualNavigation();
|
||||
void listRef.current?.scrollToIndex({
|
||||
@@ -1741,6 +1751,7 @@ function TimelineMinimap({
|
||||
currentIndex,
|
||||
items,
|
||||
stripMap,
|
||||
onWheel,
|
||||
onSelect,
|
||||
}: {
|
||||
hasPersistentGutter: boolean;
|
||||
@@ -1748,9 +1759,18 @@ function TimelineMinimap({
|
||||
currentIndex: number | null;
|
||||
items: ReadonlyArray<TimelineMinimapItem>;
|
||||
stripMap: Map<string, HTMLSpanElement>;
|
||||
onWheel: (event: WheelEvent) => void;
|
||||
onSelect: (item: TimelineMinimapItem) => void;
|
||||
}) {
|
||||
const [activeIndex, setActiveIndex] = useState<number | null>(null);
|
||||
const wheelTargetRef = useCallback(
|
||||
(node: HTMLDivElement | null) => {
|
||||
if (!node) return;
|
||||
node.addEventListener("wheel", onWheel, { passive: false });
|
||||
return () => node.removeEventListener("wheel", onWheel);
|
||||
},
|
||||
[onWheel],
|
||||
);
|
||||
|
||||
const resolvedActiveIndex =
|
||||
activeIndex !== null && activeIndex < items.length ? activeIndex : null;
|
||||
@@ -1825,6 +1845,7 @@ function TimelineMinimap({
|
||||
)}
|
||||
data-testid="timeline-minimap"
|
||||
data-persistent-gutter={hasPersistentGutter ? "true" : "false"}
|
||||
ref={wheelTargetRef}
|
||||
>
|
||||
<div className="relative h-full w-full select-none">
|
||||
<div
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { describe, expect, it, vi } from "vite-plus/test";
|
||||
|
||||
import { forwardWheelToTimeline } from "./timelineMinimapWheel";
|
||||
|
||||
function setup() {
|
||||
const timeline = document.createElement("div");
|
||||
const minimap = document.createElement("div");
|
||||
Object.defineProperty(timeline, "clientHeight", { value: 500 });
|
||||
const scrollBy = vi.fn();
|
||||
timeline.scrollBy = scrollBy as typeof timeline.scrollBy;
|
||||
const seen: WheelEvent[] = [];
|
||||
timeline.addEventListener("wheel", (event) => seen.push(event));
|
||||
minimap.addEventListener("wheel", (event) => forwardWheelToTimeline(event, timeline));
|
||||
document.body.append(timeline, minimap);
|
||||
const wheel = (init: WheelEventInit) => {
|
||||
const event = new WheelEvent("wheel", { bubbles: true, cancelable: true, ...init });
|
||||
minimap.dispatchEvent(event);
|
||||
return event;
|
||||
};
|
||||
return { timeline, scrollBy, seen, wheel };
|
||||
}
|
||||
|
||||
describe("forwardWheelToTimeline", () => {
|
||||
it("replays the wheel on the timeline and scrolls it instead of the minimap", () => {
|
||||
const { timeline, scrollBy, seen, wheel } = setup();
|
||||
const original = wheel({ deltaY: -120, clientX: 20, clientY: 300 });
|
||||
|
||||
expect(original.defaultPrevented).toBe(true);
|
||||
expect(seen).toHaveLength(1);
|
||||
expect(seen[0]?.target).toBe(timeline);
|
||||
expect(seen[0]?.deltaY).toBe(-120);
|
||||
expect(seen[0]?.clientY).toBe(300);
|
||||
expect(scrollBy).toHaveBeenCalledWith({ top: -120 });
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ deltaMode: WheelEvent.DOM_DELTA_LINE, top: 48 },
|
||||
{ deltaMode: WheelEvent.DOM_DELTA_PAGE, top: 1500 },
|
||||
])("converts delta mode $deltaMode to pixels", ({ deltaMode, top }) => {
|
||||
const { scrollBy, wheel } = setup();
|
||||
wheel({ deltaY: 3, deltaMode });
|
||||
expect(scrollBy).toHaveBeenCalledWith({ top });
|
||||
});
|
||||
|
||||
it("lets a timeline listener cancel the scroll", () => {
|
||||
const { timeline, scrollBy, wheel } = setup();
|
||||
timeline.addEventListener("wheel", (event) => event.preventDefault());
|
||||
wheel({ deltaY: 40 });
|
||||
expect(scrollBy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([{ deltaY: 40, ctrlKey: true }, { deltaX: 40 }])(
|
||||
"leaves pinch zoom and horizontal wheels alone: %j",
|
||||
(init) => {
|
||||
const { scrollBy, seen, wheel } = setup();
|
||||
expect(wheel(init).defaultPrevented).toBe(false);
|
||||
expect(seen).toHaveLength(0);
|
||||
expect(scrollBy).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
export function forwardWheelToTimeline(event: WheelEvent, timeline: HTMLElement): void {
|
||||
if (event.defaultPrevented || event.ctrlKey || event.deltaY === 0) return;
|
||||
event.preventDefault();
|
||||
|
||||
const forwarded = new WheelEvent("wheel", {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
deltaX: event.deltaX,
|
||||
deltaY: event.deltaY,
|
||||
deltaZ: event.deltaZ,
|
||||
deltaMode: event.deltaMode,
|
||||
clientX: event.clientX,
|
||||
clientY: event.clientY,
|
||||
screenX: event.screenX,
|
||||
screenY: event.screenY,
|
||||
altKey: event.altKey,
|
||||
metaKey: event.metaKey,
|
||||
shiftKey: event.shiftKey,
|
||||
});
|
||||
if (!timeline.dispatchEvent(forwarded)) return;
|
||||
|
||||
const pixelsPerUnit =
|
||||
event.deltaMode === WheelEvent.DOM_DELTA_LINE
|
||||
? 16
|
||||
: event.deltaMode === WheelEvent.DOM_DELTA_PAGE
|
||||
? timeline.clientHeight
|
||||
: 1;
|
||||
timeline.scrollBy({ top: event.deltaY * pixelsPerUnit });
|
||||
}
|
||||
Reference in new issue
Block a user