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.

fix(ide): select terminal text with a plain left-drag while the CLI tracks the mouse

rubenluetke10-beepee6f9519a581
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
index a144aba1f8..9595aadbee 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -129,6 +129,7 @@ import {
bindTerminalScrollRegion,
captureWheelForTerminalHistory,
} from "./terminalScrollSurface";
+import { installMouseSelection } from "./terminalMouseSelection";
import {
openPaneSocket,
type PaneSocket,
@@ -889,6 +890,9 @@ export function AgenticTerminal({
// ordinary click on an OSC-8 link as navigation and shows a native
// warning dialog inside the desktop WebView.
linkHandler: createTerminalOscLinkHandler(linkOptions),
+ // Lets Option force a selection on macOS while a CLI has mouse tracking
+ // on — the chord ./terminalMouseSelection marks every plain press with.
+ macOptionClickForcesSelection: true,
// Windows only. ConPTY re-emits and re-wraps lines in a way a POSIX pty
// never does; without telling xterm which backend it is talking to, those
// re-emitted lines pile up as duplicated, half-overwritten rows. Harmless
@@ -956,6 +960,9 @@ export function AgenticTerminal({
// one working, silently. See ./terminalKeyChain.
const keys = createKeyEventChain(term);
const isMac = /mac|iphone|ipad/i.test(navigator.userAgent);
+ // A plain left-button drag selects text even while the agent's CLI has
+ // mouse tracking on, which every coding agent negotiates at start-up.
+ const disposeMouseSelection = installMouseSelection(container, term, isMac);
// The desktop IDE reserves its platform copy chord for copying. In
// particular, an unselected Ctrl+C on Windows/Linux must not reach Codex
// as `^C`, where it cancels the current turn or exits the pane.
@@ -2006,6 +2013,7 @@ export function AgenticTerminal({
ro.disconnect();
io?.disconnect();
disposeFontSync();
+ disposeMouseSelection();
disposeCopyBridge();
disposePasteBridge();
disposeNewlineBridge();
diff --git a/jarvis/ui/web/frontend/src/components/agentic/terminalMouseSelection.test.ts b/jarvis/ui/web/frontend/src/components/agentic/terminalMouseSelection.test.ts
new file mode 100644
index 0000000000..5ea4266a6d
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/terminalMouseSelection.test.ts
@@ -0,0 +1,64 @@
+import { describe, expect, it } from "vitest";
+import { installMouseSelection } from "./terminalMouseSelection";
+
+/** Dispatch a press on a child of `container` and read what xterm would see. */
+function press(
+ container: HTMLElement,
+ init: MouseEventInit,
+): { shiftKey: boolean; altKey: boolean } {
+ const inner = document.createElement("div");
+ container.appendChild(inner);
+ let seen = { shiftKey: false, altKey: false };
+ inner.addEventListener("mousedown", (event) => {
+ seen = { shiftKey: event.shiftKey, altKey: event.altKey };
+ });
+ inner.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, ...init }));
+ inner.remove();
+ return seen;
+}
+
+function setup(tracking: string, isMac = false) {
+ const container = document.createElement("div");
+ const dispose = installMouseSelection(
+ container,
+ { modes: { mouseTrackingMode: tracking } },
+ isMac,
+ );
+ return { container, dispose };
+}
+
+describe("installMouseSelection", () => {
+ it("marks a plain left press as xterm's force-selection chord while tracking is on", () => {
+ const { container } = setup("any");
+ expect(press(container, { button: 0 })).toEqual({ shiftKey: true, altKey: false });
+ });
+
+ it("uses Option on macOS", () => {
+ const { container } = setup("drag", true);
+ expect(press(container, { button: 0 })).toEqual({ shiftKey: false, altKey: true });
+ });
+
+ it("leaves presses alone when the CLI has no mouse tracking", () => {
+ const { container } = setup("none");
+ expect(press(container, { button: 0 })).toEqual({ shiftKey: false, altKey: false });
+ });
+
+ it("keeps the right button and modified presses for the CLI", () => {
+ const { container } = setup("any");
+ expect(press(container, { button: 2 })).toEqual({ shiftKey: false, altKey: false });
+ expect(press(container, { button: 0, ctrlKey: true })).toEqual({
+ shiftKey: false,
+ altKey: false,
+ });
+ expect(press(container, { button: 0, altKey: true })).toEqual({
+ shiftKey: false,
+ altKey: true,
+ });
+ });
+
+ it("stops marking once disposed", () => {
+ const { container, dispose } = setup("any");
+ dispose();
+ expect(press(container, { button: 0 })).toEqual({ shiftKey: false, altKey: false });
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/agentic/terminalMouseSelection.ts b/jarvis/ui/web/frontend/src/components/agentic/terminalMouseSelection.ts
new file mode 100644
index 0000000000..58f5d8224c
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/terminalMouseSelection.ts
@@ -0,0 +1,49 @@
+/**
+ * A left-button drag in a pane always selects text.
+ *
+ * Coding-agent CLIs (Claude Code, Codex, ...) negotiate mouse tracking the
+ * moment they start. From then on xterm hands every press to the CLI as a
+ * mouse report and disables its own selection, so holding the left button and
+ * dragging across the output selected nothing at all — only xterm's hidden
+ * escape hatch (Shift on Windows/Linux, Option on macOS) still selected. Nobody
+ * knows that chord, and copying an agent's output is something people do all
+ * day.
+ *
+ * So an UNMODIFIED primary press is marked as that escape-hatch chord before
+ * xterm sees it: xterm then keeps it away from the CLI and starts a selection,
+ * exactly as if the chord had been held. Everything else still reaches the CLI
+ * as before — the right and middle buttons, the wheel, hover motion, and any
+ * press with a modifier held (Ctrl/Alt-click is the way to click INTO a CLI
+ * that wants the mouse).
+ *
+ * Only public DOM is touched: the event is marked in the capture phase on the
+ * pane's container, which runs before both of xterm's own listeners on the
+ * elements inside it. macOS additionally needs xterm's
+ * `macOptionClickForcesSelection` option, which the pane sets.
+ */
+
+/** The xterm surface this module reads — narrowed so tests can hand in fakes. */
+export interface MouseModeSource {
+ modes: { mouseTrackingMode: string };
+}
+
+/**
+ * Mark plain primary presses inside `container` as selection presses while the
+ * CLI in `term` has mouse tracking on. Returns the disposer.
+ */
+export function installMouseSelection(
+ container: HTMLElement,
+ term: MouseModeSource,
+ isMac: boolean,
+): () => void {
+ const onMouseDown = (event: MouseEvent) => {
+ if (event.button !== 0) return;
+ if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return;
+ if ((term.modes?.mouseTrackingMode ?? "none") === "none") return;
+ // Own properties shadow the prototype getters for every later listener of
+ // this one dispatch; the browser itself never reads them back.
+ Object.defineProperty(event, isMac ? "altKey" : "shiftKey", { value: true });
+ };
+ container.addEventListener("mousedown", onMouseDown, { capture: true });
+ return () => container.removeEventListener("mousedown", onMouseDown, { capture: true });
+}