Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(editor): follow mode reads one file across several columns (#686)

Ruben Lütke5682a908f7bd
diff --git a/docs/code-editor.md b/docs/code-editor.md
index b0d0961419..d9dff92984 100644
--- a/docs/code-editor.md
+++ b/docs/code-editor.md
@@ -21,6 +21,7 @@ terminals back without closing a file.
| Search in all files | **Ctrl+Shift+F** opens the **Search** tab: match case, whole word, regular expressions, include/exclude globs, and **Replace all** (a second click confirms; files with unsaved changes are left out) |
| See what changed | Coloured marks in the gutter (added, modified, deleted lines against the last commit), the **Changes** tab, or **Show changes**: the file against the last commit, editable on the right |
| Rendered view | **Ctrl+Shift+V** for Markdown, HTML and SVG |
+| Follow mode | **Follow mode** above the text lays one file out over as many columns as the width fits (two to six), each continuing on the line after the last full line of the column before it. Scrolling any column scrolls them all; the arrow keys walk the cursor from the bottom of one column into the top of the next and back, and typing works in every column. The setting belongs to the tab; a reload starts it off |
| Encoding, line endings | Click them in the status bar: reopen or save with another encoding, switch between LF and CRLF |
| Tabs | **Ctrl+W** closes, **Ctrl+Tab** switches, **Ctrl+Shift+T** reopens the last closed tab. A single click opens a preview tab (italic) that the next single click replaces; a double click or an edit keeps it |
diff --git a/jarvis/ui/web/frontend/src/components/agentic/editor/CodeEditorStage.tsx b/jarvis/ui/web/frontend/src/components/agentic/editor/CodeEditorStage.tsx
index 2c53132fe3..e6d5f2ffd9 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/editor/CodeEditorStage.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/editor/CodeEditorStage.tsx
@@ -5,6 +5,7 @@ import {
ChevronRight,
Code2,
Columns2,
+ Columns3,
Copy,
Eye,
ExternalLink,
@@ -145,6 +146,15 @@ export function CodeEditorStage({
});
const toggleRenderedRef = useRef(toggleRendered);
toggleRenderedRef.current = toggleRendered;
+ // Tabs read in follow mode: the file continues over several columns.
+ const [following, setFollowing] = useState<ReadonlySet<string>>(() => new Set());
+ const toggleFollowing = (key: string) =>
+ setFollowing((current) => {
+ const next = new Set(current);
+ if (next.has(key)) next.delete(key);
+ else next.add(key);
+ return next;
+ });
const menuAnchor = useRef<HTMLElement | null>(null);
const pushToast = useEventStore((state) => state.pushToast);
@@ -528,6 +538,16 @@ export function CodeEditorStage({
wide
/>
)}
+ {shownTab.mode === "edit" && shownFile?.status === "ready" && !rendered.has(shownTab.key) && (
+ <ActionButton
+ onClick={() => toggleFollowing(shownTab.key)}
+ icon={<Columns3 className="h-3.5 w-3.5" aria-hidden />}
+ label={t("code_editor.follow_mode")}
+ description={t("code_editor.follow_mode_description")}
+ pressed={following.has(shownTab.key)}
+ testId="code-editor-follow"
+ />
+ )}
{/* A text comparison only means something for a text file. */}
{(shownTab.mode === "diff" || shownFile?.status === "ready") && (
<ActionButton
@@ -577,6 +597,7 @@ export function CodeEditorStage({
<EditorSurface
tab={shownTab}
rendered={rendered.has(shownTab.key)}
+ follow={following.has(shownTab.key)}
focused={group.focused}
secondary={groups.length > 1}
onOpenExternally={openExternally}
@@ -747,6 +768,9 @@ function ActionButton({
hint,
iconOnly = false,
wide = false,
+ pressed,
+ testId,
+ description,
}: {
onClick: () => void;
icon: ReactNode;
@@ -755,14 +779,24 @@ function ActionButton({
iconOnly?: boolean;
/** Keep the label visible at every window width. */
wide?: boolean;
+ /** A switch: on or off, shown by its colour. */
+ pressed?: boolean;
+ testId?: string;
+ /** A sentence for the tooltip in place of the label. */
+ description?: string;
}) {
return (
<button
type="button"
onClick={onClick}
- title={hint ? `${label} (${hint})` : label}
+ title={description ?? (hint ? `${label} (${hint})` : label)}
aria-label={label}
- className="inline-flex h-6 shrink-0 items-center gap-1.5 rounded px-1.5 text-xs text-muted-foreground hover:bg-secondary hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
+ aria-pressed={pressed}
+ data-testid={testId}
+ className={cn(
+ "inline-flex h-6 shrink-0 items-center gap-1.5 rounded px-1.5 text-xs text-muted-foreground hover:bg-secondary hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
+ pressed && "bg-primary/15 text-primary hover:bg-primary/20 hover:text-primary",
+ )}
>
{icon}
{!iconOnly && <span className={wide ? "inline" : "hidden xl:inline"}>{label}</span>}
diff --git a/jarvis/ui/web/frontend/src/components/agentic/editor/EditorSurface.tsx b/jarvis/ui/web/frontend/src/components/agentic/editor/EditorSurface.tsx
index f7b3b0038f..e65f1be4eb 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/editor/EditorSurface.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/editor/EditorSurface.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useRef, type MouseEvent } from "react";
+import { useEffect, useRef, useState, type MouseEvent } from "react";
import { Loader2 } from "lucide-react";
import { fill, useT } from "@/i18n";
@@ -9,6 +9,8 @@ import { gutterChanges } from "./lineDiff";
import { EDITOR_OPTIONS, applyTheme, monaco } from "./monacoRuntime";
import { renderKindOf } from "./fileKinds";
import { ExtractedPreview, MediaViewer, Notice, RenderedPreview } from "./FileViewers";
+import { followColumnCount } from "./followLayout";
+import { followColumns, type FollowColumns } from "./followMode";
type CodeEditor = monaco.editor.ICodeEditor;
@@ -49,10 +51,14 @@ const keepContextMenu = (event: MouseEvent) => event.stopPropagation();
* The text area of the code editor: one long-lived editor for every edit tab
* (switching tabs swaps the model and restores that tab's cursor and scroll)
* and one diff editor, created the first time a Changes entry is opened.
+ *
+ * In follow mode the edit tab's text continues in further columns beside the
+ * long-lived editor, as many as the width fits.
*/
export default function EditorSurface({
tab,
rendered,
+ follow = false,
focused = true,
secondary = false,
onOpenExternally,
@@ -67,10 +73,18 @@ export default function EditorSurface({
secondary?: boolean;
/** Show a Markdown, HTML or SVG file rendered instead of its source. */
rendered: boolean;
+ /** Lay the file out over several columns that read on from each other. */
+ follow?: boolean;
onOpenExternally: (path: string) => void;
}) {
const t = useT();
const codeHost = useRef<HTMLDivElement>(null);
+ const columnsHost = useRef<HTMLDivElement>(null);
+ const followHosts = useRef<(HTMLDivElement | null)[]>([]);
+ const followRef = useRef<FollowColumns | null>(null);
+ // The follow-mode columns after the first one; empty while follow mode is off.
+ const [followers, setFollowers] = useState<monaco.editor.IStandaloneCodeEditor[]>([]);
+ const [columnCount, setColumnCount] = useState(2);
const diffHost = useRef<HTMLDivElement>(null);
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor | null>(null);
const diffRef = useRef<monaco.editor.IStandaloneDiffEditor | null>(null);
@@ -85,6 +99,7 @@ export default function EditorSurface({
const status = file?.status ?? "loading";
const ready = status === "ready";
const renderKind = renderKindOf(tab.path);
+ const following = follow && ready && tab.mode === "edit" && !(rendered && renderKind);
// Follow the app's light/dark switch. Watching the class on <html> (not a
// prop) matters: the theme provider repaints the document in its own effect,
@@ -106,6 +121,9 @@ export default function EditorSurface({
return () => {
if (shown.current) rememberViewState(shown.current, editor.saveViewState());
for (const watcher of watchers) watcher.dispose();
+ // The follow columns let go of the lead editor before it goes away.
+ followRef.current?.dispose();
+ followRef.current = null;
editor.dispose();
diffRef.current?.dispose();
diffRef.current = null;
@@ -145,8 +163,36 @@ export default function EditorSurface({
(tab.mode === "diff" ? diffRef.current?.getModifiedEditor() : editorRef.current)?.focus();
}, [focused, ready, tab.mode]);
+ // Follow mode: as many columns as the width fits, re-counted as it changes.
+ useEffect(() => {
+ const host = columnsHost.current;
+ if (!following || !host) return;
+ const measure = () => setColumnCount(followColumnCount(host.clientWidth));
+ measure();
+ const observer = new ResizeObserver(measure);
+ observer.observe(host);
+ return () => observer.disconnect();
+ }, [following]);
+
+ useEffect(() => {
+ const editor = editorRef.current;
+ const hosts = followHosts.current.slice(0, columnCount - 1);
+ if (!following || !editor || hosts.length !== columnCount - 1 || hosts.some((host) => !host)) return;
+ const columns = followColumns(editor, hosts as HTMLDivElement[]);
+ followRef.current = columns;
+ const watchers = columns.editors.flatMap(watchCursor);
+ setFollowers(columns.editors);
+ return () => {
+ for (const watcher of watchers) watcher.dispose();
+ columns.dispose();
+ if (followRef.current === columns) followRef.current = null;
+ setFollowers([]);
+ };
+ }, [following, columnCount]);
+
// Gutter markers against the last commit: green added, blue modified, a red
- // notch where lines were deleted. Recomputed shortly after each edit.
+ // notch where lines were deleted. Recomputed shortly after each edit, in
+ // every follow-mode column too.
useEffect(() => {
const editor = editorRef.current;
const model = modelOf(tab.fileKey);
@@ -154,27 +200,26 @@ export default function EditorSurface({
let alive = true;
let base: string | null = null;
let timer: number | undefined;
- const collection = editor.createDecorationsCollection();
+ const collections = [editor, ...followers].map((column) => column.createDecorationsCollection());
const paint = () => {
if (!alive || base === null || editor.getModel() !== model) {
- collection.clear();
+ for (const collection of collections) collection.clear();
return;
}
const lines = model.getLineCount();
const changes = gutterChanges(base, model.getValue()) ?? [];
- collection.set(
- changes.map((change) => {
- const below = change.kind === "deleted" && change.start > lines;
- const start = Math.min(change.start, lines);
- return {
- range: new monaco.Range(start, 1, Math.min(change.end, lines), 1),
- options: {
- isWholeLine: true,
- linesDecorationsClassName: below ? "jarvis-gutter-deleted-below" : `jarvis-gutter-${change.kind}`,
- },
- };
- }),
- );
+ const decorations = changes.map((change) => {
+ const below = change.kind === "deleted" && change.start > lines;
+ const start = Math.min(change.start, lines);
+ return {
+ range: new monaco.Range(start, 1, Math.min(change.end, lines), 1),
+ options: {
+ isWholeLine: true,
+ linesDecorationsClassName: below ? "jarvis-gutter-deleted-below" : `jarvis-gutter-${change.kind}`,
+ },
+ };
+ });
+ for (const collection of collections) collection.set(decorations);
};
void loadHeadText(tab.fileKey).then((text) => {
base = text;
@@ -188,9 +233,9 @@ export default function EditorSurface({
alive = false;
window.clearTimeout(timer);
listener.dispose();
- collection.clear();
+ for (const collection of collections) collection.clear();
};
- }, [tab.key, tab.fileKey, tab.mode, ready]);
+ }, [tab.key, tab.fileKey, tab.mode, ready, followers]);
// Diff tabs: the committed text on the left, the live (editable) buffer on the right.
const diffBaseRef = useCodeEditorStore((state) => state.diffBases[tab.fileKey]?.ref ?? "");
@@ -287,7 +332,26 @@ export default function EditorSurface({
const showCode = ready && tab.mode === "edit";
return (
<div className="relative h-full min-h-0 w-full" data-testid="code-editor-surface" data-language={languageFor(tab.path)}>
- <div ref={codeHost} onContextMenu={keepContextMenu} className={cn("absolute inset-0", !showCode && "invisible")} />
+ <div
+ ref={columnsHost}
+ onContextMenu={keepContextMenu}
+ data-testid="code-editor-columns"
+ data-follow={following ? columnCount : undefined}
+ className={cn("absolute inset-0 flex", !showCode && "invisible")}
+ >
+ <div ref={codeHost} className="relative h-full min-w-0 flex-1" />
+ {following &&
+ Array.from({ length: columnCount - 1 }, (_, index) => (
+ <div
+ key={index}
+ ref={(host) => {
+ followHosts.current[index] = host;
+ }}
+ data-testid="code-editor-follow-column"
+ className="relative h-full min-w-0 flex-1 border-l border-border/70"
+ />
+ ))}
+ </div>
{/* `hidden`, not `invisible`: Monaco's diff widget writes an inline
`visibility: visible` on both of its halves, which overrides a hidden
parent — the last diff then stayed painted over the next edit tab. */}
diff --git a/jarvis/ui/web/frontend/src/components/agentic/editor/followLayout.test.ts b/jarvis/ui/web/frontend/src/components/agentic/editor/followLayout.test.ts
new file mode 100644
index 0000000000..517aed03c0
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/editor/followLayout.test.ts
@@ -0,0 +1,65 @@
+import { describe, expect, it } from "vitest";
+
+import {
+ FOLLOW_COLUMNS_MAX,
+ clampFollowTop,
+ followColumnCount,
+ followColumnOf,
+ followOffset,
+ followStep,
+} from "./followLayout";
+
+describe("follow mode layout", () => {
+ it("fits as many columns as the width allows, at least two and at most the cap", () => {
+ expect(followColumnCount(300)).toBe(2);
+ expect(followColumnCount(1000)).toBe(2);
+ expect(followColumnCount(1800)).toBe(4);
+ expect(followColumnCount(20000)).toBe(FOLLOW_COLUMNS_MAX);
+ });
+
+ it("steps each column by the full lines that fit one column below the space above the first line", () => {
+ expect(followStep(610, 20)).toBe(600);
+ expect(followStep(600, 20)).toBe(600);
+ expect(followStep(610, 20, 8)).toBe(600);
+ expect(followStep(605, 20, 8)).toBe(580);
+ // A column shorter than a line still moves the next one by a line.
+ expect(followStep(12, 20)).toBe(20);
+ });
+
+ it("starts every later column on a line boundary, skipping the space above the first line", () => {
+ // Lines start at 8, 28, 48, …: 8 px of blank space above the first line.
+ expect(followOffset(0, 0, 600, 8)).toBe(0);
+ expect(followOffset(0, 1, 600, 8)).toBe(608);
+ expect(followOffset(0, 2, 600, 8)).toBe(1208);
+ expect(followOffset(100, 1, 600, 8)).toBe(708);
+ });
+
+ it("keeps the first column between the file's start and the point where its end fills the last column", () => {
+ // 100 lines of 20 px, 3 columns of 200 px each.
+ expect(clampFollowTop(-50, 2000, 200, 200, 3)).toBe(0);
+ expect(clampFollowTop(500, 2000, 200, 200, 3)).toBe(500);
+ expect(clampFollowTop(5000, 2000, 200, 200, 3)).toBe(1400);
+ expect(clampFollowTop(5000, 2016, 200, 180, 3, 8)).toBe(1448);
+ // A file shorter than the surface never scrolls.
+ expect(clampFollowTop(300, 400, 200, 200, 3)).toBe(0);
+ });
+
+ it("names the column a line is shown in", () => {
+ // First column scrolled to 100 px, columns 200 px apart.
+ expect(followColumnOf(100, 100, 200, 3)).toBe(0);
+ expect(followColumnOf(299, 100, 200, 3)).toBe(0);
+ expect(followColumnOf(300, 100, 200, 3)).toBe(1);
+ expect(followColumnOf(699, 100, 200, 3)).toBe(2);
+ // Above the first column and below the last one: off the surface.
+ expect(followColumnOf(80, 100, 200, 3)).toBeNull();
+ expect(followColumnOf(700, 100, 200, 3)).toBeNull();
+ });
+
+ it("gives the first column the space above the first line as well", () => {
+ // Unscrolled, 8 px lead: the first column shows lines starting at 8 … 588.
+ expect(followColumnOf(588, 0, 600, 2, 8)).toBe(0);
+ expect(followColumnOf(608, 0, 600, 2, 8)).toBe(1);
+ expect(followColumnOf(1188, 0, 600, 2, 8)).toBe(1);
+ expect(followColumnOf(1208, 0, 600, 2, 8)).toBeNull();
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/agentic/editor/followLayout.ts b/jarvis/ui/web/frontend/src/components/agentic/editor/followLayout.ts
new file mode 100644
index 0000000000..27a91bf683
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/editor/followLayout.ts
@@ -0,0 +1,68 @@
+/**
+ * The arithmetic of follow mode: one file laid out over several columns that
+ * read on from each other, the way a newspaper page does.
+ *
+ * The first column scrolls to `top`; every later column `index` scrolls to
+ * `top + index * step + lead`, so it starts on the line after the last full
+ * line of the column before it. `lead` is the blank space the editor keeps
+ * above the first line: the first column shows it, the others skip it. Kept
+ * free of the editor engine so the maths can be tested on its own.
+ */
+
+/** Narrower than this, a column cuts off too much of an ordinary line of code. */
+export const FOLLOW_COLUMN_MIN_PX = 440;
+/** More columns than this stop being readable on any monitor. */
+export const FOLLOW_COLUMNS_MAX = 6;
+
+/** How many columns fit a text area this wide; follow mode always shows at least two. */
+export function followColumnCount(width: number): number {
+ return Math.max(2, Math.min(FOLLOW_COLUMNS_MAX, Math.floor(width / FOLLOW_COLUMN_MIN_PX)));
+}
+
+/**
+ * How far each column scrolls past the one before it: the full lines that fit
+ * one column below the blank space above the first line. A line cut off at
+ * the bottom of a column is the first line of the next one, so no line is
+ * ever missing.
+ */
+export function followStep(viewportHeight: number, lineHeight: number, lead = 0): number {
+ if (lineHeight <= 0) return Math.max(1, viewportHeight - lead);
+ return Math.max(lineHeight, Math.floor((viewportHeight - lead) / lineHeight) * lineHeight);
+}
+
+/** Where column `index` scrolls to when the first one is at `top`. */
+export function followOffset(top: number, index: number, step: number, lead = 0): number {
+ return index === 0 ? top : top + index * step + lead;
+}
+
+/**
+ * The scroll offset of the first column, kept in range: never above the
+ * file's start, and never further down than the point where the file's end
+ * reaches the bottom of the last column.
+ */
+export function clampFollowTop(
+ top: number,
+ contentHeight: number,
+ viewportHeight: number,
+ step: number,
+ count: number,
+ lead = 0,
+): number {
+ const last = followOffset(0, count - 1, step, lead);
+ const max = Math.max(0, contentHeight - viewportHeight - last);
+ return Math.min(max, Math.max(0, top));
+}
+
+/**
+ * The column that shows a line starting `lineTop` pixels into the file, with
+ * the first column scrolled to `top`; null when no column shows it.
+ */
+export function followColumnOf(lineTop: number, top: number, step: number, count: number, lead = 0): number | null {
+ if (lineTop < top || step <= 0) return null;
+ for (let index = count - 1; index >= 0; index -= 1) {
+ if (lineTop >= followOffset(top, index, step, lead)) {
+ return index === count - 1 && lineTop >= followOffset(top, count, step, lead) ? null : index;
+ }
+ }
+ return null;
+}
diff --git a/jarvis/ui/web/frontend/src/components/agentic/editor/followMode.ts b/jarvis/ui/web/frontend/src/components/agentic/editor/followMode.ts
new file mode 100644
index 0000000000..80b3638eca
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/editor/followMode.ts
@@ -0,0 +1,150 @@
+import { EDITOR_OPTIONS, monaco } from "./monacoRuntime";
+import { clampFollowTop, followColumnOf, followOffset, followStep } from "./followLayout";
+
+type CodeEditor = monaco.editor.IStandaloneCodeEditor;
+
+/**
+ * What every column turns off while follow mode is on. A minimap or a
+ * sticky header would take lines out of the text, and a folded region in one
+ * column would shift every column after it. Scrolling is immediate: an
+ * animated scroll would still be moving the columns after a cursor has
+ * already been handed to the next one.
+ */
+const FOLLOW_OPTIONS: monaco.editor.IEditorOptions = {
+ minimap: { enabled: false },
+ stickyScroll: { enabled: false },
+ folding: false,
+ smoothScrolling: false,
+};
+
+/** The lead editor's own settings, put back when follow mode ends. */
+const LEAD_RESTORE: monaco.editor.IEditorOptions = {
+ minimap: EDITOR_OPTIONS.minimap,
+ stickyScroll: EDITOR_OPTIONS.stickyScroll,
+ folding: true,
+ smoothScrolling: EDITOR_OPTIONS.smoothScrolling,
+};
+
+export interface FollowColumns {
+ /** The columns after the lead one, left to right. */
+ editors: CodeEditor[];
+ dispose(): void;
+}
+
+/**
+ * Follow mode: the file in `lead` continues in `hosts.length` more columns.
+ *
+ * Every column edits the same text. Scrolling any of them scrolls the whole
+ * surface, and a cursor that walks off the bottom (or top) of a column with
+ * the keyboard carries on in the next (or previous) column instead of
+ * scrolling the text under it.
+ */
+export function followColumns(lead: CodeEditor, hosts: HTMLElement[]): FollowColumns {
+ const columns: CodeEditor[] = [lead];
+ for (const host of hosts) {
+ columns.push(
+ monaco.editor.create(host, {
+ ...EDITOR_OPTIONS,
+ ...FOLLOW_OPTIONS,
+ // A later column of a short file scrolls past the file's end.
+ scrollBeyondLastLine: true,
+ model: lead.getModel(),
+ theme: "jarvis",
+ }),
+ );
+ }
+ lead.updateOptions(FOLLOW_OPTIONS);
+
+ const lineHeight = () => lead.getOption(monaco.editor.EditorOption.lineHeight);
+ // The text a column shows: the horizontal scrollbar covers its bottom edge.
+ const viewport = () => {
+ const layout = lead.getLayoutInfo();
+ return layout.height - layout.horizontalScrollbarHeight;
+ };
+ // The blank space above the first line, which only the first column shows.
+ const above = () => lead.getOption(monaco.editor.EditorOption.padding).top;
+ const step = () => followStep(viewport(), lineHeight(), above());
+ // Where the last line ends, without the blank space below it.
+ const textEnd = () => lead.getContentHeight() - lead.getOption(monaco.editor.EditorOption.padding).bottom;
+
+ // The first column's scroll offset; the others follow it (see followLayout).
+ let top = lead.getScrollTop();
+ let applying = false;
+
+ const apply = () => {
+ const room = step();
+ const space = above();
+ const end = textEnd();
+ applying = true;
+ try {
+ columns.forEach((editor, index) => {
+ const wanted = followOffset(top, index, room, space);
+ if (Math.abs(editor.getScrollTop() - wanted) > 0.5) editor.setScrollTop(wanted, monaco.editor.ScrollType.Immediate);
+ // A column that starts below the file's end stays empty.
+ if (index > 0) editor.getDomNode()!.style.visibility = wanted >= end ? "hidden" : "";
+ });
+ } finally {
+ applying = false;
+ }
+ };
+
+ const moveTo = (next: number) => {
+ top = clampFollowTop(next, lead.getContentHeight(), viewport(), step(), columns.length, above());
+ apply();
+ };
+
+ const watchers: monaco.IDisposable[] = [];
+ columns.forEach((editor, index) => {
+ watchers.push(
+ editor.onDidScrollChange((event) => {
+ if (applying || !event.scrollTopChanged) return;
+ moveTo(event.scrollTop - followOffset(0, index, step(), above()));
+ }),
+ editor.onDidChangeCursorSelection((event) => {
+ // Only the keyboard walks the cursor from column to column; a click
+ // or a jump to a line lands where it was asked to.
+ if (event.source !== "keyboard" || !editor.hasTextFocus()) return;
+ const before = top;
+ const line = event.selection.getPosition().lineNumber;
+ const target = followColumnOf(editor.getTopForLineNumber(line), before, step(), columns.length, above());
+ if (target === null) return;
+ // The editor scrolls its cursor into view right after this event
+ // (with a line of air below it). The line is on the surface already,
+ // so that scroll is undone once it has happened.
+ queueMicrotask(() => {
+ if (Math.abs(top - before) > 0.5) moveTo(before);
+ if (target === index) return;
+ const next = columns[target];
+ next.setSelections(editor.getSelections() ?? [event.selection]);
+ next.focus();
+ });
+ }),
+ );
+ });
+ watchers.push(
+ // A new tab in the lead editor shows in every column, from its own scroll offset.
+ lead.onDidChangeModel(() => {
+ const model = lead.getModel();
+ for (const editor of columns.slice(1)) editor.setModel(model);
+ moveTo(lead.getScrollTop());
+ }),
+ lead.onDidLayoutChange(() => moveTo(top)),
+ lead.onDidContentSizeChange(() => moveTo(top)),
+ );
+
+ moveTo(top);
+
+ let disposed = false;
+ return {
+ editors: columns.slice(1),
+ dispose() {
+ // The surface ends follow mode both when it is turned off and when the
+ // lead editor goes away; only the first call acts.
+ if (disposed) return;
+ disposed = true;
+ for (const watcher of watchers) watcher.dispose();
+ for (const editor of columns.slice(1)) editor.dispose();
+ lead.updateOptions(LEAD_RESTORE);
+ },
+ };
+}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index 91efa26d21..a654171969 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -7445,6 +7445,8 @@
"deleted": "Diese Datei wurde auf der Festplatte gelöscht. Speichern legt sie neu an.",
"preview": "Vorschau",
"show_source": "Quelltext zeigen",
+ "follow_mode": "Follow-Modus",
+ "follow_mode_description": "Diese Datei über mehrere Spalten lesen, die aneinander anschließen",
"media_failed": "Diese Datei lässt sich hier nicht anzeigen.",
"document_note": "Aus diesem Dokument gelesener Text. Zum Bearbeiten auf diesem Computer öffnen.",
"truncated": "Nur der Anfang der Datei wird gezeigt.",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index 7ab83be843..91a104d2e7 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -7445,6 +7445,8 @@
"deleted": "This file was deleted on disk. Saving creates it again.",
"preview": "Preview",
"show_source": "Show source",
+ "follow_mode": "Follow mode",
+ "follow_mode_description": "Read this file across several columns that continue one another",
"media_failed": "This file cannot be shown here.",
"document_note": "Text read out of this document. Open it on this computer to edit it.",
"truncated": "Only the beginning of the file is shown.",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index 2f8fa76c25..5070a88e3e 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -7445,6 +7445,8 @@
"deleted": "Este archivo se eliminó del disco. Al guardar se vuelve a crear.",
"preview": "Vista previa",
"show_source": "Ver código",
+ "follow_mode": "Modo continuo",
+ "follow_mode_description": "Leer este archivo en varias columnas que continúan una tras otra",
"media_failed": "Este archivo no se puede mostrar aquí.",
"document_note": "Texto leído de este documento. Ábrelo en este equipo para editarlo.",
"truncated": "Solo se muestra el comienzo del archivo.",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/pt.json b/jarvis/ui/web/frontend/src/i18n/locales/pt.json
index ee70e52643..0a5a4e3004 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/pt.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/pt.json
@@ -7445,6 +7445,8 @@
"deleted": "Este ficheiro foi eliminado do disco. Guardar volta a criá-lo.",
"preview": "Pré-visualizar",
"show_source": "Mostrar código-fonte",
+ "follow_mode": "Modo contínuo",
+ "follow_mode_description": "Ler este ficheiro em várias colunas que continuam umas nas outras",
"media_failed": "Este ficheiro não pode ser mostrado aqui.",
"document_note": "Texto extraído deste documento. Abre-o neste computador para o editar.",
"truncated": "Só é mostrado o início do ficheiro.",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/zh.json b/jarvis/ui/web/frontend/src/i18n/locales/zh.json
index c4f98a19ea..a220f5e24f 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/zh.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/zh.json
@@ -7445,6 +7445,8 @@
"deleted": "此文件已在磁盘上被删除。保存会重新创建它。",
"preview": "预览",
"show_source": "显示源码",
+ "follow_mode": "跟随模式",
+ "follow_mode_description": "在多个相互衔接的列中阅读此文件",
"media_failed": "此文件无法在这里显示。",
"document_note": "这是从文档中读取的文本。要编辑,请在这台电脑上打开它。",
"truncated": "只显示了文件的开头部分。",