Add VS Code open support and stabilize chat autoscroll

- add VS Code to editor contracts and picker UI
- use `code --goto` for line/column targets in open resolution
- refine chat scroll intent handling to avoid unwanted stick-to-bottom jumps
This commit is contained in:
Julius Marminge committed 2026-03-02 16:06:17 -08:00
1 parent 1b0093a483
commit ecb4a1efa4
4 files changed
+113 -12

No files matched your search

+22 -4
View File
@@ -5,20 +5,29 @@ import { Effect } from "effect";
import { assertSuccess } from "@effect/vitest/utils";
describe("resolveEditorLaunch", () => {
it.effect("returns cursor command for cursor editor", () =>
it.effect("returns commands for command-based editors", () =>
Effect.gen(function* () {
const launch = yield* resolveEditorLaunch(
const cursorLaunch = yield* resolveEditorLaunch(
{ cwd: "/tmp/workspace", editor: "cursor" },
"darwin",
);
assert.deepEqual(launch, {
assert.deepEqual(cursorLaunch, {
command: "cursor",
args: ["/tmp/workspace"],
});
const vscodeLaunch = yield* resolveEditorLaunch(
{ cwd: "/tmp/workspace", editor: "vscode" },
"darwin",
);
assert.deepEqual(vscodeLaunch, {
command: "code",
args: ["/tmp/workspace"],
});
}),
);
it.effect("uses --goto when cursor target includes line/column suffixes", () =>
it.effect("uses --goto when editor supports line/column suffixes", () =>
Effect.gen(function* () {
const lineOnly = yield* resolveEditorLaunch(
{ cwd: "/tmp/workspace/AGENTS.md:48", editor: "cursor" },
@@ -37,6 +46,15 @@ describe("resolveEditorLaunch", () => {
command: "cursor",
args: ["--goto", "/tmp/workspace/src/open.ts:71:5"],
});
const vscodeLineAndColumn = yield* resolveEditorLaunch(
{ cwd: "/tmp/workspace/src/open.ts:71:5", editor: "vscode" },
"darwin",
);
assert.deepEqual(vscodeLineAndColumn, {
command: "code",
args: ["--goto", "/tmp/workspace/src/open.ts:71:5"],
});
}),
);
+1 -1
View File
@@ -33,7 +33,7 @@ interface EditorLaunch {
const LINE_COLUMN_SUFFIX_PATTERN = /:\d+(?::\d+)?$/;
function shouldUseGotoFlag(editorId: EditorId, target: string): boolean {
return editorId === "cursor" && LINE_COLUMN_SUFFIX_PATTERN.test(target);
return (editorId === "cursor" || editorId === "vscode") && LINE_COLUMN_SUFFIX_PATTERN.test(target);
}
/**
+89 -7
View File
@@ -517,6 +517,10 @@ export default function ChatView({ threadId }: ChatViewProps) {
const messagesScrollRef = useRef<HTMLDivElement>(null);
const [messagesScrollElement, setMessagesScrollElement] = useState<HTMLDivElement | null>(null);
const shouldAutoScrollRef = useRef(true);
const lastKnownScrollTopRef = useRef(0);
const isPointerScrollActiveRef = useRef(false);
const lastTouchClientYRef = useRef<number | null>(null);
const pendingUserScrollUpIntentRef = useRef(false);
const pendingAutoScrollFrameRef = useRef<number | null>(null);
const composerEditorRef = useRef<ComposerPromptEditorHandle>(null);
const composerCommandInputRef = useRef<HTMLInputElement>(null);
@@ -1324,8 +1328,15 @@ export default function ChatView({ threadId }: ChatViewProps) {
const scrollContainer = messagesScrollRef.current;
if (!scrollContainer) return;
scrollContainer.scrollTo({ top: scrollContainer.scrollHeight, behavior });
lastKnownScrollTopRef.current = scrollContainer.scrollTop;
shouldAutoScrollRef.current = true;
}, []);
const cancelPendingStickToBottom = useCallback(() => {
const pendingFrame = pendingAutoScrollFrameRef.current;
if (pendingFrame === null) return;
pendingAutoScrollFrameRef.current = null;
window.cancelAnimationFrame(pendingFrame);
}, []);
const scheduleStickToBottom = useCallback(() => {
if (pendingAutoScrollFrameRef.current !== null) return;
pendingAutoScrollFrameRef.current = window.requestAnimationFrame(() => {
@@ -1333,19 +1344,77 @@ export default function ChatView({ threadId }: ChatViewProps) {
scrollMessagesToBottom();
});
}, [scrollMessagesToBottom]);
const forceStickToBottom = useCallback(() => {
cancelPendingStickToBottom();
scrollMessagesToBottom();
scheduleStickToBottom();
}, [cancelPendingStickToBottom, scheduleStickToBottom, scrollMessagesToBottom]);
const onMessagesScroll = useCallback(() => {
const scrollContainer = messagesScrollRef.current;
if (!scrollContainer) return;
shouldAutoScrollRef.current = isScrollContainerNearBottom(scrollContainer);
const currentScrollTop = scrollContainer.scrollTop;
const isNearBottom = isScrollContainerNearBottom(scrollContainer);
if (!shouldAutoScrollRef.current && isNearBottom) {
shouldAutoScrollRef.current = true;
pendingUserScrollUpIntentRef.current = false;
} else if (shouldAutoScrollRef.current && pendingUserScrollUpIntentRef.current) {
const scrolledUp = currentScrollTop < lastKnownScrollTopRef.current - 1;
if (scrolledUp) {
shouldAutoScrollRef.current = false;
}
pendingUserScrollUpIntentRef.current = false;
} else if (shouldAutoScrollRef.current && isPointerScrollActiveRef.current) {
const scrolledUp = currentScrollTop < lastKnownScrollTopRef.current - 1;
if (scrolledUp) {
shouldAutoScrollRef.current = false;
}
} else if (shouldAutoScrollRef.current && !isNearBottom) {
// Catch-all for keyboard/assistive scroll interactions.
const scrolledUp = currentScrollTop < lastKnownScrollTopRef.current - 1;
if (scrolledUp) {
shouldAutoScrollRef.current = false;
}
}
lastKnownScrollTopRef.current = currentScrollTop;
}, []);
const onMessagesWheel = useCallback((event: React.WheelEvent<HTMLDivElement>) => {
if (event.deltaY < 0) {
pendingUserScrollUpIntentRef.current = true;
}
}, []);
const onMessagesPointerDown = useCallback((_event: React.PointerEvent<HTMLDivElement>) => {
isPointerScrollActiveRef.current = true;
}, []);
const onMessagesPointerUp = useCallback((_event: React.PointerEvent<HTMLDivElement>) => {
isPointerScrollActiveRef.current = false;
}, []);
const onMessagesPointerCancel = useCallback((_event: React.PointerEvent<HTMLDivElement>) => {
isPointerScrollActiveRef.current = false;
}, []);
const onMessagesTouchStart = useCallback((event: React.TouchEvent<HTMLDivElement>) => {
const touch = event.touches[0];
if (!touch) return;
lastTouchClientYRef.current = touch.clientY;
}, []);
const onMessagesTouchMove = useCallback((event: React.TouchEvent<HTMLDivElement>) => {
const touch = event.touches[0];
if (!touch) return;
const previousTouchY = lastTouchClientYRef.current;
if (previousTouchY !== null && touch.clientY > previousTouchY + 1) {
pendingUserScrollUpIntentRef.current = true;
}
lastTouchClientYRef.current = touch.clientY;
}, []);
const onMessagesTouchEnd = useCallback((_event: React.TouchEvent<HTMLDivElement>) => {
lastTouchClientYRef.current = null;
}, []);
useEffect(() => {
return () => {
const frame = pendingAutoScrollFrameRef.current;
if (frame !== null) {
window.cancelAnimationFrame(frame);
}
cancelPendingStickToBottom();
};
}, []);
}, [cancelPendingStickToBottom]);
useLayoutEffect(() => {
if (!activeThread?.id) return;
shouldAutoScrollRef.current = true;
@@ -1922,7 +1991,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
]);
// Sending a message should always bring the latest user turn into view.
shouldAutoScrollRef.current = true;
scheduleStickToBottom();
forceStickToBottom();
setThreadError(threadIdForSend, null);
promptRef.current = "";
@@ -2442,6 +2511,14 @@ export default function ChatView({ threadId }: ChatViewProps) {
ref={setMessagesScrollContainerRef}
className="min-h-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-y-contain px-3 py-3 sm:px-5 sm:py-4"
onScroll={onMessagesScroll}
onWheel={onMessagesWheel}
onPointerDown={onMessagesPointerDown}
onPointerUp={onMessagesPointerUp}
onPointerCancel={onMessagesPointerCancel}
onTouchStart={onMessagesTouchStart}
onTouchMove={onMessagesTouchMove}
onTouchEnd={onMessagesTouchEnd}
onTouchCancel={onMessagesTouchEnd}
>
<MessagesTimeline
key={activeThread.id}
@@ -3602,6 +3679,11 @@ const OpenInPicker = memo(function OpenInPicker({
Icon: CursorIcon,
value: "cursor",
},
{
label: "VS Code",
Icon: FileIcon,
value: "vscode",
},
{
label: isMacPlatform(navigator.platform)
? "Finder"
+1
View File
@@ -3,6 +3,7 @@ import { TrimmedNonEmptyString } from "./baseSchemas";
export const EDITORS = [
{ id: "cursor", label: "Cursor", command: "cursor" },
{ id: "vscode", label: "VS Code", command: "code" },
{ id: "file-manager", label: "File Manager", command: null },
] as const;