Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: leave editor undo alone

Samrat Talukdare8e40cd23272
diff --git a/apps/app/src/react-app/domains/session/commands/undo-key.ts b/apps/app/src/react-app/domains/session/commands/undo-key.ts
index fd0d93c1..5cad7896 100644
--- a/apps/app/src/react-app/domains/session/commands/undo-key.ts
+++ b/apps/app/src/react-app/domains/session/commands/undo-key.ts
@@ -8,6 +8,8 @@ export function chatUndoKey(event: Pick<KeyboardEvent, "key" | "metaKey" | "ctrl
const target = event.target as HTMLElement | null;
if (target && typeof target === "object" && "tagName" in target) {
if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.tagName === "SELECT") return null;
+ // Code editors and terminals keep their own undo, whatever element holds their focus.
+ if (typeof target.closest === "function" && target.closest(".monaco-editor, .xterm, .cm-editor")) return null;
if (target.isContentEditable && (target.textContent ?? "").replace(/[\u200B\uFEFF]/g, "").trim().length > 0) return null;
}
return event.shiftKey ? "redo" : "undo";
diff --git a/apps/app/tests/session-commands.test.ts b/apps/app/tests/session-commands.test.ts
index 36fea4c9..a99750d1 100644
--- a/apps/app/tests/session-commands.test.ts
+++ b/apps/app/tests/session-commands.test.ts
@@ -168,5 +168,7 @@ describe("chatUndoKey", () => {
expect(chatUndoKey(key({ metaKey: true, target: { tagName: "TEXTAREA", isContentEditable: false, textContent: "" } }), true)).toBeNull();
expect(chatUndoKey(key({ metaKey: true, target: { tagName: "DIV", isContentEditable: true, textContent: "draft" } }), true)).toBeNull();
expect(chatUndoKey(key({ metaKey: true, target: { tagName: "DIV", isContentEditable: true, textContent: " " } }), true)).toBe("undo");
+ const inEditor = { tagName: "DIV", isContentEditable: false, textContent: "", closest: (selector: string) => (selector.includes(".monaco-editor") ? {} : null) };
+ expect(chatUndoKey(key({ ctrlKey: true, target: inEditor }), false)).toBeNull();
});
});