Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: gutter diff bounds and editor key cleanup

ogsamrat2f0938f20685
diff --git a/apps/app/src/react-app/domains/session/editor/editor-surface.tsx b/apps/app/src/react-app/domains/session/editor/editor-surface.tsx
index b113c3c9..47de1c2f 100644
--- a/apps/app/src/react-app/domains/session/editor/editor-surface.tsx
+++ b/apps/app/src/react-app/domains/session/editor/editor-surface.tsx
@@ -150,12 +150,17 @@ export function EditorSurface({ monaco, surface, onSave, onCursor, onHunks, navi
const modified = diff.getModifiedEditor() as MonacoApi.editor.IStandaloneCodeEditor;
// Keys scoped per editor (monaco.ts scopeEditor): Monaco shares keybindings between editors.
const contexts = new Map<MonacoApi.editor.IStandaloneCodeEditor, string>([[code, scopeEditor(code, "code")], [modified, scopeEditor(modified, "diff")]]);
- code.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, save, contexts.get(code));
- modified.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, save, contexts.get(modified));
+ const saveAction = (editor: MonacoApi.editor.IStandaloneCodeEditor) => editor.addAction({
+ id: "omnirush.editor.save",
+ label: "Save",
+ keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS],
+ keybindingContext: contexts.get(editor),
+ run: save,
+ });
const cursor = (editor: MonacoApi.editor.ICodeEditor) => editor.onDidChangeCursorPosition((event) => {
onCursorRef.current({ line: event.position.lineNumber, column: event.position.column });
});
- const disposables = [cursor(code), cursor(diff.getModifiedEditor())];
+ const disposables = [cursor(code), cursor(diff.getModifiedEditor()), saveAction(code), saveAction(modified)];
// The agent in the editor: first in the right-click menu, and Cmd/Ctrl+L to ask. Monaco always sorts its
// "navigation" group first, so the agent items join it with orders below Go to Definition (1.1).
const agentActions = (editor: MonacoApi.editor.IStandaloneCodeEditor) => ([
diff --git a/apps/app/src/react-app/domains/session/editor/line-diff.ts b/apps/app/src/react-app/domains/session/editor/line-diff.ts
index 057edc23..a2d1463a 100644
--- a/apps/app/src/react-app/domains/session/editor/line-diff.ts
+++ b/apps/app/src/react-app/domains/session/editor/line-diff.ts
@@ -39,8 +39,9 @@ export function diffLines(before: readonly string[], after: readonly string[], m
else if (m === 0 && n > 0) middle.push({ kind: "delete", count: n });
else if (n > 0 && m > 0) {
const max = n + m;
- const offset = max;
- const v = new Int32Array(2 * max + 2);
+ // One spare slot at each end: the band read at step d spans diagonals -(d+1)..d+1, and d can reach max.
+ const offset = max + 1;
+ const v = new Int32Array(2 * max + 3);
// trace[d]: v for diagonals -(d+1)..d+1 before step d (the walk back reads k-1 and k+1), at index k + d + 1.
const trace: Int32Array[] = [];
let found = -1;
diff --git a/apps/app/src/react-app/domains/session/editor/markdown-preview.tsx b/apps/app/src/react-app/domains/session/editor/markdown-preview.tsx
index fdc7e128..769a889e 100644
--- a/apps/app/src/react-app/domains/session/editor/markdown-preview.tsx
+++ b/apps/app/src/react-app/domains/session/editor/markdown-preview.tsx
@@ -73,6 +73,11 @@ export function MarkdownPreview(props: {
const src = image.getAttribute("src") ?? "";
image.removeAttribute("srcset");
image.removeAttribute("src");
+ // Inline images (data:image/…) load nothing from anywhere: shown as they are.
+ if (/^data:image\/(png|jpe?g|gif|webp|avif|bmp)[;,]/i.test(src)) {
+ image.setAttribute("src", src);
+ continue;
+ }
if (/^[a-z][a-z0-9+.-]*:/i.test(src) || src.startsWith("//")) {
const note = document.createElement("span");
note.className = "my-2 inline-block rounded-md border border-dashed border-border px-2 py-1 text-xs text-muted-foreground";
@@ -108,7 +113,11 @@ export function MarkdownPreview(props: {
if (!url) {
url = props.client.editorRaw(props.workspaceId, target).then(
(result) => URL.createObjectURL(new Blob([result.data], { type: result.contentType ?? "application/octet-stream" })),
- () => null,
+ () => {
+ // Not cached: the image may appear or be fixed while the preview is open.
+ imageUrls.current.delete(target);
+ return null;
+ },
);
imageUrls.current.set(target, url);
}
diff --git a/apps/app/src/react-app/domains/session/editor/monaco.ts b/apps/app/src/react-app/domains/session/editor/monaco.ts
index 31daad80..03c89bf3 100644
--- a/apps/app/src/react-app/domains/session/editor/monaco.ts
+++ b/apps/app/src/react-app/domains/session/editor/monaco.ts
@@ -156,6 +156,7 @@ export function addGroupKeys(monaco: Monaco, editor: MonacoApi.editor.IStandalon
label: "Open Markdown preview to the side",
keybindings: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyV],
keybindingContext: context,
+ precondition: "editorLangId == 'markdown'",
run: () => {
window.dispatchEvent(new CustomEvent("omnirush:editor-command", { detail: "preview-side" }));
},
diff --git a/apps/app/tests/line-diff.test.ts b/apps/app/tests/line-diff.test.ts
index 2a4835e7..62bcf8d7 100644
--- a/apps/app/tests/line-diff.test.ts
+++ b/apps/app/tests/line-diff.test.ts
@@ -57,3 +57,39 @@ describe("git gutter line diff on large files", () => {
expect(gutterMarks(head, current)).toBeNull();
});
});
+
+describe("git gutter line diff: no common line in the changed region", () => {
+ test("two lines replaced by two others", () => {
+ expect(diffLines(["x", "q"], ["y", "r"])).toEqual([{ kind: "delete", count: 2 }, { kind: "insert", count: 2 }]);
+ });
+
+ test("two lines replaced by one is a single change", () => {
+ expect(gutterMarks("a\nx\nz\nb", "a\ny\nb")).toEqual([{ kind: "change", startLine: 2, endLine: 2, removed: 2 }]);
+ });
+
+ test("random edits always rebuild the new text", () => {
+ let seed = 7;
+ const random = () => ((seed = (seed * 1103515245 + 12345) % 2147483648) / 2147483648);
+ for (let round = 0; round < 2000; round += 1) {
+ const before = Array.from({ length: Math.floor(random() * 8) }, () => "abc"[Math.floor(random() * 3)]!);
+ const after = Array.from({ length: Math.floor(random() * 8) }, () => "abc"[Math.floor(random() * 3)]!);
+ const edits = diffLines(before, after)!;
+ const rebuilt: string[] = [];
+ let i = 0;
+ let j = 0;
+ for (const edit of edits) {
+ if (edit.kind === "equal") {
+ rebuilt.push(...before.slice(i, i + edit.count));
+ i += edit.count;
+ j += edit.count;
+ } else if (edit.kind === "delete") i += edit.count;
+ else {
+ rebuilt.push(...after.slice(j, j + edit.count));
+ j += edit.count;
+ }
+ }
+ expect(i).toBe(before.length);
+ expect(rebuilt).toEqual(after);
+ }
+ });
+});