fix(tui): pop inputBuf on backspace when composer is empty - #22254
Closed
wesleysimplicio wants to merge 1 commit into
Closed
fix(tui): pop inputBuf on backspace when composer is empty#22254wesleysimplicio wants to merge 1 commit into
wesleysimplicio wants to merge 1 commit into
Conversation
Sub-issue of NousResearch#22034 (NousResearch#18394 specifically). The composer's `\` + Enter continuation aggregator (in useSubmission.ts) pushes each line into a `inputBuf` array and clears the active input. The previously buffered lines live OUTSIDE the textInput's `value`, so its internal backspace handler can never reach them — pressing Backspace from an empty input was a no-op, leaving accumulated lines stranded until submission. Users typing `77\<Enter>\<Enter>\<Enter>88` were stuck with 3 invisible newlines that no Backspace could remove. Fix: at the global useInputHandlers layer, when Backspace is pressed and the input is empty AND the buffer has content, pop the last buffered line back into the input as the new editable value. This restores the expected per-character / per-line undo behaviour and stays a no-op when the input is non-empty (textInput keeps owning normal backspace). Logic is extracted as a pure helper `popInputBufOnEmptyBackspace` so it can be unit-tested without the full Ink hook surface.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a TUI composer edge case where Backspace from an empty input could not “reach” previously buffered continuation lines (created via the \ + Enter multi-line aggregator), leaving those lines stranded until submission.
Changes:
- Added a global Backspace handler that, when
input === ''andinputBufis non-empty, pops the last buffered line back into the editable input. - Extracted the pop behavior into a pure helper (
popInputBufOnEmptyBackspace) to keep the hook logic simple and testable. - Added unit tests covering the helper’s behavior, including no-op cases and non-mutation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| ui-tui/src/app/useInputHandlers.ts | Adds popInputBufOnEmptyBackspace and wires it into the global Backspace handling path to restore buffered continuation lines when the input is empty. |
| ui-tui/src/tests/useInputHandlers.test.ts | Adds focused unit tests for popInputBufOnEmptyBackspace, including edge cases and immutability. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
Closing — PR has merge conflicts that can't be auto-resolved. The codebase has evolved past this fix. Re-opening with a fresh rebase welcome if the issue is still open. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Sub-issue of #22034 (specifically #18394 — "TUI backspace cannot delete newline characters in composer input").
Root cause
The detailed rationale from the original PR body is preserved below. This template update keeps the review structure consistent with #29640.
Fix
Why this shape
This shape mirrors #29640 so reviewers can quickly compare scope, root cause, fix, tests, and related context without having to decode a custom PR description.
Tests
Original body
Related PRs / issues
Original body
Summary
Sub-issue of #22034 (specifically #18394 — "TUI backspace cannot delete newline characters in composer input").
What Changed
Fluxo
A mudança continua seguindo o fluxo original descrito na seção preservada abaixo, sem ampliar o escopo funcional deste PR.
Visão
A padronização melhora a revisão, reduz ruído e evita deriva de formatação entre PRs abertos.
Test Plan
Original body
Summary
Sub-issue of #22034 (specifically #18394 — "TUI backspace cannot delete newline characters in composer input").
The composer aggregates multi-line input via
\+ Enter by pushing each typed line into ainputBufarray and clearing the active input (useSubmission.ts:402-406). Those buffered lines live outside the textInput's value, so the textInput's internal Backspace handler can never reach them — Backspace from an empty input was a no-op, leaving accumulated lines stranded until submission.This PR adds a global Backspace handler in
useInputHandlersthat, when the input is empty and the buffer is non-empty, pops the last buffered line back into the input as the new editable value. Normal Backspace (input non-empty) still belongs to textInput.The pop logic is extracted as a pure helper
popInputBufOnEmptyBackspaceso it is unit-tested in isolation without rebuilding the full Ink hook surface.Test plan
useInputHandlers.test.ts(10/10 in file pass) — empty buffer, single-line buffer, multi-line buffer, empty-string buffered line, non-mutation guarantee, no-op when input is non-emptynpx vitest run→ 655/655 passGenerated by Hermes Turbo
Generated by Hermes Turbo