Skip to content

fix(tui): show the whole value when text goes in at the start of the Custom Command and Link editors - #785

Merged
sirmalloc merged 1 commit into
sirmalloc:mainfrom
eric-engberg:fix/ink-split-text-relayout
Nov 5, 2026
Merged

sirmalloc merged 1 commit into
sirmalloc:mainfrom
eric-engberg:fix/ink-split-text-relayout

Conversation

@eric-engberg

Copy link
Copy Markdown
Contributor

What

Text pasted or typed into the Custom Command and Link editors with the cursor at the start, as in an empty field, now shows in full. On main the field kept the line's old width, so it showed only part of the value until the next key, though Enter saved all of it.

Why

Ink 6.2.0's insertBeforeNode (build/dom.js) returns early when it inserts a node before an existing sibling. That skips the markNodeAsDirty call that appendChildNode and its own append branch make. Yoga then reuses the text's old measurement, and Ink wraps the line at the old width onto rows the layout never reserved, where the next row draws over them.

The Custom Command and Link editors render the value as three siblings inside one <Text>: value.slice(0, cursor), the cursor cell and the rest. With the cursor at the start, the first part is an empty string, which React renders as no node. So the next input inserts a new text node ahead of the cursor cell, which takes the early-return path.

On main:

  • Built dist/ in tmux (110 columns) under Bun 1.4.2 and Node 26.10.0, with npx ccusage statusline pasted in one write into an empty Custom Command field: Enter command path: npx ccusage.
  • The same paste in the TUI run from source (the demo below): Enter saves the whole command, and the widget row then shows Custom Command (npx ccusage statu...).
  • In the TUI test harness (120 columns):
    • The same paste, then Left: the whole line comes back.
    • Link (u)rl, pasting https://github.com/sirmalloc/ccstatusline: the field shows Enter URL (http/https): https://github, and the row below reads Current text: (uses URL)ine.
    • Link (e)dit text, pasting ccstatusline on GitHub: the field shows Enter link text (blank uses URL): with nothing after it, and the row below reads Current URL: (none)Hub.
    • Custom Command opened on npx -y ccusage@latest statusline --offline, Left to the start, then x: Enter command path: xnpx -y ccusage@latest statusline. --offline comes back with the next key.

The editor is as wide as its widest row, here the 38-column help line ←→ move cursor, Enter save, ESC cancel. Before the paste the field row was laid out at that width, and Yoga keeps it. Ink wraps the pasted line at 38 columns, and the next row draws over the second line. That's why the URL is cut at exactly column 38 and its tail (ine) shows past the end of the shorter row below.

Ink fixed this upstream in 6.8.0: vadimdemedes/ink#879 (for vadimdemedes/ink#867) marks the node dirty after both branches.

How

  • patches/ink@6.2.0.patch gets a second hunk, for build/dom.js. insertBeforeNode no longer returns early, so both the insert and the append branch reach the existing markNodeAsDirty call. The function now matches Ink 6.8.0's build/dom.js line for line. The backspace hunk is unchanged.
    • The patch was made with bun patch ink@6.2.0 and bun patch --commit node_modules/ink, minus the empty .bun-tag-* file entry bun adds.
    • package.json and bun.lock don't change, since the lockfile records only the patch's path. bun install --frozen-lockfile from a clean checkout applies both hunks.
  • Ink is a devDependency bundled into dist/, so the built CLI carries the patched insertBeforeNode.
  • New src/tui/__tests__/ink-patch.test.tsx: a <Box><Text> with the editors' split ('Command: ', the part before the cursor, an inverse cursor cell, the rest).
    • It renders statusline with the cursor at the start, then rerenders npx ccusage statusline with the cursor on the same s. Only the part before the cursor changes, from no node to a new one, and the test expects the whole line.
    • It waits on the rendered frame, never on a fixed delay. It fails on main with Received: "Command: npx".
  • AGENTS.md (which CLAUDE.md links to) now lists both fixes in the patch and how to regenerate it. The install note in docs/DEVELOPMENT.md names both.

Left as is:

  • Ink stays at 6.2.0. This carries the one upstream hunk instead of moving to 6.8.0 or later, which would bring several releases of other changes with it.

Demo

The real TUI on main (before) and this branch (after). npx ccusage statusline is pasted into the empty Custom Command (e)dit cmd field in one write, the way a terminal pastes, then Enter saves it. Before, the field shows only npx ccusage, although the widget row (npx ccusage statu...) and the preview (cmd: npx ccusage statusli...) then show that more than that was saved. After, the field shows all of it.

Powerline

Before:

Pasting a command into an empty Custom Command field in Powerline mode before the fix

After:

Pasting a command into an empty Custom Command field in Powerline mode after the fix

Plain

Before:

Pasting a command into an empty Custom Command field in plain mode before the fix

After:

Pasting a command into an empty Custom Command field in plain mode after the fix

Testing

  • On main as of fix: use env override and settings for usable context ratio calculation #407 (71e8b42): merges cleanly, bun run lint is clean, and bun test gives 3939 pass, 0 fail. The built CLI under Bun 1.4.4 and Node 26.13.0 matches main in plain and Powerline mode with the baseline configs, and the TUI opens and exits cleanly. It adds no JavaScript or Node API newer than Node 14, the build's target.
  • bun run lint: clean.
  • bun test: 3169 pass, 0 fail across 179 files. With main's patch: 3168 pass, 1 fail (the new test) across 179 files.
  • Full suite under vitest on Node 26.10.0 (node node_modules/vitest/vitest.mjs run), 3146 tests in 179 files:
    • This branch: 2960 pass, 186 fail. With main's patch: 2959 pass, 187 fail.
    • The only difference is the new test, which fails with main's patch (expected 'Command: npx') and passes here.
    • The other 186 are the same tests on both: ESM spy failures (vi.spyOn on os.homedir, child_process exports and others) and the usage-fetch subprocess suite.
  • runtime-check.sh on Bun 1.4.2 and Node 26.10.0: piped renders in plain and Powerline mode are the same as main, with both runtimes agreeing. The TUI opens and exits cleanly on both.
  • Built dist/ in tmux under Bun 1.4.2 and Node 26.10.0, with npx ccusage statusline pasted into an empty Custom Command field: main shows npx ccusage, and this branch shows npx ccusage statusline on both runtimes.

Ink 6.2.0's insertBeforeNode returns early when it inserts a node before
an existing sibling, so it never marks the parent text dirty the way
appendChildNode (and its own append branch) do. Yoga keeps the text's
old measured size, and Ink wraps the line at the old width onto rows
the layout never reserved, where the next row draws over it. It stays
that way until something re-measures the text, such as the next key.

The Custom Command and Link editors render the value as three sibling
texts: the part before the cursor, the cursor cell and the rest. With
the cursor at the start, as in an empty field, the part before it
renders nothing, so the next input inserts a new text ahead of the
cursor cell. Pasting "npx ccusage statusline" into an empty Custom
Command field showed only "npx ccusage", though Enter saved the whole
command. A URL or link text pasted into an empty Link field was cut the
same way, with its cut-off end showing at the end of the next row. A
key typed at the start of a command that was already the editor's
widest row hid the command's last word.

Add a hunk to the ink patch that marks the node dirty after both
branches, as Ink does upstream from 6.8.0.
@axisrow

axisrow commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Reproduced on current main (66e9a08):

Red: the new ink-patch.test.tsx fails against unpatched ink 6.2.0 exactly as described — inserting text before the cursor cell renders only a stale prefix: Expected: "Command: npx ccusage statusline" / Received: "Command: npx".

Green: after a fresh bun install in the PR head worktree (applying the updated patches/ink@6.2.0.patch), the test passes 1 / 1 — the patch applies cleanly from the lockfile + patch file.

bun test on macOS.

@sirmalloc
sirmalloc merged commit ccda60c into sirmalloc:main Nov 5, 2026
3 checks passed
@sirmalloc

Copy link
Copy Markdown
Owner

Nice one, this has always annoyed me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants