Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(terminal): count the copied body, not the newline stripped from it

enesd112f8eda211
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 2fdbaf0c1..bdbdf7a24 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -666,6 +666,11 @@ export function TerminalNode({
const termRef = useRef<Terminal | null>(null)
// Copy feedback: the `Copied` pill (fed by the OSC 52 handler below, through `copySubs`) and the
// one-time "hold ⌥ to select" hint for a pane whose app captured the mouse.
+ // The host is `bodyRef` (`.term-node__xterm`) and NOT the node body on purpose: the hover guard
+ // (`.term-hover-guard`) is a SIBLING of that element, so pre-dwell drags — the ones that MOVE the
+ // node — never reach this listener. Hosting it on `.term-node__body` would make every node-move
+ // drag a hint candidate and burn the once-per-installation hint on a gesture that has nothing to
+ // do with copying.
const copy = useCopyFeedback({
hostRef: bodyRef,
hasSelection: () => !!termRef.current?.hasSelection()
diff --git a/src/renderer/terminal/copy-feedback.test.ts b/src/renderer/terminal/copy-feedback.test.ts
index 870e12bc8..8dd884e27 100644
--- a/src/renderer/terminal/copy-feedback.test.ts
+++ b/src/renderer/terminal/copy-feedback.test.ts
@@ -14,9 +14,15 @@ describe('copiedLabel', () => {
it('does not count a trailing newline as an extra line', () => {
expect(copiedLabel('a\nb\n')).toBe('Copied 2 lines')
})
+ it('does not count a trailing newline as an extra character', () => {
+ expect(copiedLabel('hello\n')).toBe('Copied 5 chars')
+ })
it('returns null for empty text — nothing was copied, so no pill', () => {
expect(copiedLabel('')).toBeNull()
})
+ it('returns null for a bare newline — the strip leaves nothing to claim', () => {
+ expect(copiedLabel('\n')).toBeNull()
+ })
})
describe('decideDragOutcome', () => {
@@ -39,6 +45,12 @@ describe('decideDragOutcome', () => {
it('stays silent below the drag threshold — a click is not a drag', () => {
expect(decideDragOutcome({ ...base, movedPx: DRAG_MIN_PX - 1 })).toBeNull()
})
+ it('hints at exactly the threshold — the boundary counts as a drag', () => {
+ expect(decideDragOutcome({ ...base, movedPx: DRAG_MIN_PX })).toEqual({
+ kind: 'hint',
+ label: 'Hold ⌥ to select text'
+ })
+ })
it('stays silent when an OSC 52 landed — the handler already put its pill up', () => {
expect(decideDragOutcome({ ...base, sawOsc52: true })).toBeNull()
})
diff --git a/src/renderer/terminal/copy-feedback.ts b/src/renderer/terminal/copy-feedback.ts
index 1dcbfcd20..5d361700c 100644
--- a/src/renderer/terminal/copy-feedback.ts
+++ b/src/renderer/terminal/copy-feedback.ts
@@ -27,19 +27,24 @@ export const HINT_DWELL_MS = 5000
* execCommand fallback runs — and dispatches its error toast — inside `writeText`, i.e. before the
* OSC 52 handler calls `notifyCopy`. Retracting after the fact cannot catch that ordering. */
export const ERROR_TOAST_SUPPRESS_MS = 50
-/** Once per installation — same convention as `seenShortcuts`. */
+/** Once per installation, and personal rather than shared config — so it is a `localStorage` key,
+ * like `nodeterm.sessionsPinned` and `nodeterm.explorerExpanded`, not a setting in `settings.json`. */
export const HINT_STORAGE_KEY = 'nodeterm.seenSelectHint'
/**
* The `copied` pill's label. Lines for multi-line text, characters for one line — the two numbers
- * a user checks when unsure the right thing was copied. Empty text yields null: nothing was
- * copied, so nothing is claimed.
+ * a user checks when unsure the right thing was copied. ONE trailing newline is stripped before
+ * BOTH counts (a copy-mode selection of a whole line, and every `vim "+y` of one line, carries it;
+ * counting it as a character made the headline number off by one in the most common case). Text
+ * with nothing left after that strip — `''` or a bare `'\n'` — yields null: nothing worth naming
+ * was copied, so nothing is claimed.
*/
export function copiedLabel(text: string): string | null {
- if (!text) return null
- const lines = text.replace(/\n$/, '').split('\n').length
+ const body = text.replace(/\n$/, '')
+ if (!body) return null
+ const lines = body.split('\n').length
if (lines > 1) return `Copied ${lines} lines`
- return `Copied ${text.length} char${text.length === 1 ? '' : 's'}`
+ return `Copied ${body.length} char${body.length === 1 ? '' : 's'}`
}
/**