Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: git gutter for unsaved edits in the first file opened

ogsamrateb1e556d4350
diff --git a/apps/app/src/react-app/domains/session/editor/editor-panel.tsx b/apps/app/src/react-app/domains/session/editor/editor-panel.tsx
index daa674af..5cf5982c 100644
--- a/apps/app/src/react-app/domains/session/editor/editor-panel.tsx
+++ b/apps/app/src/react-app/domains/session/editor/editor-panel.tsx
@@ -1020,8 +1020,8 @@ export default function EditorPanel(props: EditorPanelProps) {
}, [gutter, gitQuery.dataUpdatedAt]);
useEffect(() => {
if (!surfaceReady || !surface || surface.kind !== "file" || !gitFiles) return;
- const editor = surfaceHandle.current?.activeEditor();
- if (!editor || editor.getModel() !== surface.doc.model) return;
+ const editor = surfaceHandle.current?.codeEditor();
+ if (!editor) return;
const doc = surface.doc;
const changedInGit = gitFiles.some((file) => file.path === doc.path);
return gutter.attach(editor, doc.model, doc.path, changedInGit, () => docs.isDirty(doc));
@@ -1210,7 +1210,6 @@ export default function EditorPanel(props: EditorPanelProps) {
useEffect(() => {
const editor = group2EditorRef.current;
if (!group2Ready || !editor || !group2Doc || group2Tab?.kind !== "file" || !gitFiles) return;
- if (editor.getModel() !== group2Doc.model) return;
const changedInGit = gitFiles.some((file) => file.path === group2Doc.path);
return gutter.attach(editor, group2Doc.model, group2Doc.path, changedInGit, () => docs.isDirty(group2Doc));
}, [docs, gitFiles, group2Doc, group2Ready, group2Tab, gutter]);
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 61fa871c..6b7bea48 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
@@ -48,6 +48,8 @@ export type AgentAction = "ask" | "explain" | "refactor" | "tests";
export type SurfaceHandle = {
reveal: (line: number, column: number, endColumn?: number) => void;
activeEditor: () => MonacoApi.editor.ICodeEditor | null;
+ /** The code (non-diff) editor, whatever is shown now (the git gutter attaches before the mode switches). */
+ codeEditor: () => MonacoApi.editor.ICodeEditor;
};
const BASE_OPTIONS: MonacoApi.editor.IStandaloneEditorConstructionOptions = {
@@ -180,6 +182,7 @@ export function EditorSurface({ monaco, surface, onSave, onCursor, onHunks, navi
editor.focus();
},
activeEditor: () => (modeRef.current === "diff" ? diff.getModifiedEditor() : modeRef.current === "file" ? code : null),
+ codeEditor: () => code,
});
// Auto save "when focus leaves": the panel listens for this.
const blurEvent = () => window.dispatchEvent(new Event("omnirush:editor-blur"));
diff --git a/apps/app/src/react-app/domains/session/editor/git-gutter.ts b/apps/app/src/react-app/domains/session/editor/git-gutter.ts
index 878dcbcc..3a564d65 100644
--- a/apps/app/src/react-app/domains/session/editor/git-gutter.ts
+++ b/apps/app/src/react-app/domains/session/editor/git-gutter.ts
@@ -74,7 +74,8 @@ export class GitGutter {
return;
}
const marks = await diffInWorker(head, current);
- if (disposed || mine !== generation || model.isDisposed()) return;
+ // Only while the editor shows this file (it may switch to it a moment after the gutter attaches).
+ if (disposed || mine !== generation || model.isDisposed() || editor.getModel() !== model) return;
decorations.set((marks ?? []).map((mark) => ({
range: { startLineNumber: Math.max(1, mark.startLine), startColumn: 1, endLineNumber: Math.max(1, mark.endLine), endColumn: 1 },
options: {
@@ -85,14 +86,19 @@ export class GitGutter {
})));
};
void update();
- const subscription = model.onDidChangeContent(() => {
+ const schedule = () => {
window.clearTimeout(timer);
timer = window.setTimeout(() => void update(), DEBOUNCE_MS);
+ };
+ const subscription = model.onDidChangeContent(schedule);
+ const modelChange = editor.onDidChangeModel(() => {
+ if (editor.getModel() === model) void update();
});
return () => {
disposed = true;
window.clearTimeout(timer);
subscription.dispose();
+ modelChange.dispose();
decorations.clear();
};
}