Skip to content

fix(tui): preserve summarized paste order with wide text#25855

Open
zclllyybb wants to merge 1 commit intoanomalyco:devfrom
zclllyybb:fix_utf8_offset
Open

fix(tui): preserve summarized paste order with wide text#25855
zclllyybb wants to merge 1 commit intoanomalyco:devfrom
zclllyybb:fix_utf8_offset

Conversation

@zclllyybb
Copy link
Copy Markdown

@zclllyybb zclllyybb commented May 5, 2026

Issue for this PR

Closes #25854

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

OpenTUI extmark ranges are display-width offsets, but the prompt submit path used them directly as JavaScript string indices when replacing virtual paste summaries with the original pasted text. If the prompt before a [Pasted ~N lines] marker contained wide characters such as Chinese, the replacement range was shifted and the submitted prompt could splice the pasted content into the wrong position.

Convert display offsets to string indices before expanding text parts, fall back to the virtual marker text when extmark offsets were adjusted using string length semantics, and size virtual extmark ranges with Bun.stringWidth. Add regression coverage for Chinese text, newlines, multiple paste summaries, and shifted extmarks.

How did you verify your code works?

I added a testcase in packages/opencode/test/cli/cmd/tui/prompt-paste.test.ts. And I have performed e2e testing locally, the following screenshots can prove the repair results.

Screenshots / recordings

when I actually enter:

我能吞下玻璃而不伤身体我能吞下玻璃而不伤身体我能吞下玻璃而不伤身体[Pasted ~1 lines]我能吞下玻璃而不伤身体。

with the pasted line:

A sufficiently long test content1 A sufficiently long test content2 A sufficiently long test content3 A sufficiently long test content1 A sufficiently long test content2 A sufficiently long test content4 A sufficiently long test content1 A sufficiently long test content2 A sufficiently long test content5 

before fix:
image

after fix:
image

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copilot AI review requested due to automatic review settings May 5, 2026 10:53
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 5, 2026
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

OpenTUI extmark ranges are display-width offsets, but the prompt submit path used them directly as JavaScript string indices when replacing virtual paste summaries with the original pasted text. If the prompt before a [Pasted ~N lines] marker contained wide characters such as Chinese, the replacement range was shifted and the submitted prompt could splice the pasted content into the wrong position.

Convert display offsets to string indices before expanding text parts, fall back to the virtual marker text when extmark offsets were adjusted using string length semantics, and size virtual extmark ranges with Bun.stringWidth. Add regression coverage for Chinese text, newlines, multiple paste summaries, and shifted extmarks.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a TUI prompt submission bug where OpenTUI extmark ranges (display-width offsets) were incorrectly treated as JavaScript string indices when expanding paste summaries, causing pasted content to be spliced into the wrong position when wide characters (e.g., Chinese) appear earlier in the prompt.

Changes:

  • Add display-offset ↔ string-index conversion utilities and a robust “virtual marker range” resolver for paste summary expansion.
  • Update prompt submission to expand pasted text via the new helper (instead of slicing by raw extmark offsets).
  • Correct extmark sizing for virtual paste/file markers using Bun.stringWidth, and add regression tests covering wide text, newlines, multiple paste summaries, and shifted extmarks.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/opencode/src/cli/cmd/tui/component/prompt/paste.ts New helper to map display offsets to string indices and expand paste-summary parts safely.
packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx Use the new expansion helper on submit; size virtual extmarks using display width.
packages/opencode/test/cli/cmd/tui/prompt-paste.test.ts Regression tests for wide characters/newlines/multiple summaries and extmark drift fallback.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Bojun-Vvibe added a commit to Bojun-Vvibe/oss-contributions that referenced this pull request May 6, 2026
- anomalyco/opencode#25959 keep-alive newlines on POST /session/:id/message [merge-after-nits]
- anomalyco/opencode#25855 wide-text paste-summary order fix via Intl.Segmenter [merge-after-nits]
- openai/codex#21290 extract codex-file-watcher crate from core [merge-after-nits]
- openai/codex#21272 add 'compact' SessionStartSource with FIFO queue [merge-after-nits]
@zclllyybb
Copy link
Copy Markdown
Author

@kitlangton @thdxr @rekram1-node Sorry to bother, but I believe this is a real correctness issue affecting many users. Can someone help to move this PR forward?

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.

[Bug] The "paste summary" causes the content to be disordered after pasting.

2 participants