Skip to content

fix(tui): preserve scrollback when closing editor-replacement dialogs - #2414

Closed
mangeshraut712 wants to merge 1 commit into
MoonshotAI:mainfrom
mangeshraut712:fix/tui-preserve-scroll-on-modal-close
Closed

fix(tui): preserve scrollback when closing editor-replacement dialogs#2414
mangeshraut712 wants to merge 1 commit into
MoonshotAI:mainfrom
mangeshraut712:fix/tui-preserve-scroll-on-modal-close

Conversation

@mangeshraut712

@mangeshraut712 mangeshraut712 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Closing permission prompts / AskUserQuestion (and other restoreEditor paths) forced a full redraw that included ESC[3J, wiping terminal scrollback and yanking anyone who had scrolled up to read history (TUI scroll position resets to top after approving a tool permission prompt #2296).
  • Add requestRender(true, { clearScrollback: false }) in pi-tui so callers can re-anchor the live viewport without clearing scrollback; wire it into restoreEditor and slash-menu close.
  • Default requestRender(true) still clears scrollback, matching prior behavior for width/height and other forced redraws.

Test plan

  • pnpm --filter @moonshot-ai/pi-tui test (716 pass), including new “forced redraw can skip clearing terminal scrollback”
  • vitest: real KimiTUI.restoreEditor() coverage in kimi-tui-startup.test.ts + custom-editor.test.ts scrollback cases
  • Manual: long session → scroll up in terminal scrollback → trigger a tool permission → approve → confirm scrollback history is still reachable
  • Manual: same for AskUserQuestion confirm
  • Manual: slash-menu open/close still re-anchors the editor at the bottom on overflow sessions

Resolves #2296

@changeset-bot

changeset-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ca8cd91

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/pi-tui Patch
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mangeshraut712

Copy link
Copy Markdown
Contributor Author

Final verification (local)

Verdict: VERIFIED — ready for review/merge from the local evidence below. GitHub Actions checks had not reported on this fork branch yet at verification time.

Check Result
pnpm --filter @moonshot-ai/pi-tui test 716/716 pass
focused kimi-code vitest (restore-editor-scrollback + custom-editor) 49/49 pass
oxlint on changed files 0 warnings/errors
tsc --noEmit (pi-tui) exit 0
Claim proof script clearScrollback:falseESC[2J ESC[H] present, ESC[3J] absent; default force still emits ESC[3J]
Perf (p50 force redraw, n=50/200/800 lines) clear=true ≈25.9/25.8/25.7 ms vs clear=false ≈25.8/26.2/26.0 ms — no meaningful regression (bound by render wait)

No further code changes planned on this PR unless review asks.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3451e886f0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +36 to +37
// Mirrors KimiTUI.restoreEditor without constructing the full TUI host.
const restoreEditor = (): void => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Drive the real restoreEditor in the regression test

Because this test defines a local copy of KimiTUI.restoreEditor instead of invoking the production method, it will keep passing if the real restoreEditor later drops { clearScrollback: false } or changes its overflow logic; the new standalone file also bypasses the repo preference to extend the existing test for the relevant module. Please move this coverage to an existing KimiTUI/TUI test and call the real method rather than a mirror.

AGENTS.md reference: AGENTS.md:L60-L60

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 63fd1da:

  • Deleted the standalone mirrored restore-editor-scrollback.test.ts
  • Moved coverage into kimi-tui-startup.test.ts
  • Tests now construct real KimiTUI and call production restoreEditor() (overflow / fits / tmux cases)

mangeshraut712 added a commit to mangeshraut712/kimi-code that referenced this pull request Jul 30, 2026
Replace the mirrored restoreEditor helper with coverage that constructs
KimiTUI and calls the production method, addressing Codex P2 on MoonshotAI#2414.

Co-authored-by: Cursor <cursoragent@cursor.com>
@mangeshraut712

Copy link
Copy Markdown
Contributor Author

Update — Codex P2 fixed

Follow-up commit 63fd1da97: regression now drives real KimiTUI.restoreEditor() from kimi-tui-startup.test.ts (standalone mirror deleted).

Re-verified locally: focused restoreEditor + custom-editor scrollback tests pass.

@mangeshraut712

Copy link
Copy Markdown
Contributor Author

Final verification (post-Codex-P2)

Check Result
pnpm --filter @moonshot-ai/pi-tui test 716/716 pass
focused kimi restoreEditor + custom-editor scrollback tests pass
Codex P2 addressed in 63fd1da97 — real KimiTUI.restoreEditor() in kimi-tui-startup.test.ts

Ready for maintainer review. Manual smoke (permission approve / AskUserQuestion / slash-menu with scrolled scrollback) still useful if a reviewer has a TTY.

lucasfelipe24 pushed a commit to lucasfelipe24/kimi-code that referenced this pull request Jul 30, 2026
Replace the mirrored restoreEditor helper with coverage that constructs
KimiTUI and calls the production method, addressing Codex P2 on MoonshotAI#2414.

Co-authored-by: Cursor <cursoragent@cursor.com>
Closing editor-replacement dialogs cleared TUI scrollback because
restoreEditor rebuilt the viewport without restoring prior history.
Preserve scrollback across restore and cover it with a regression test
that drives the real restoreEditor path.
@mangeshraut712
mangeshraut712 force-pushed the fix/tui-preserve-scroll-on-modal-close branch from 63fd1da to ca8cd91 Compare July 30, 2026 17:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca8cd916cd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@@ -0,0 +1,5 @@
---
"@moonshot-ai/pi-tui": patch

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Drop the private pi-tui changeset

This changeset targets @moonshot-ai/pi-tui, but the repo's changeset instructions say release changesets should only select @moonshot-ai/kimi-code or @moonshot-ai/kimi-code-sdk (.changeset/README.md:149), and internal-package fixes that affect the CLI should be represented by the affected publishable package (.changeset/README.md:150). Since this PR already adds a @moonshot-ai/kimi-code changeset for the user-visible behavior, leaving this file makes the release metadata include a private internal package instead of staying limited to publishable artifacts, so please remove it.

Useful? React with 👍 / 👎.

@liruifengv liruifengv closed this Aug 1, 2026
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.

TUI scroll position resets to top after approving a tool permission prompt

2 participants