GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(tui): correct pasted preview replacement for CJK and multi-width characters by AbigailJixiangyuyu · Pull Request #17034 · anomalyco/opencode

Conversation

@AbigailJixiangyuyu

@AbigailJixiangyuyu AbigailJixiangyuyu commented Mar 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #17032

Type of change

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

What does this PR do?

Fix a TUI bug where [Pasted ~N lines] preview tokens are not correctly replaced when the prompt contains CJK characters before the paste.

The previous implementation used terminal visual column offsets but performed the replacement using JavaScript string slicing. This works for ASCII input but becomes misaligned for multi-width characters such as Chinese, Japanese and Korean.

This PR converts the visual column offsets to the correct string indices before performing the replacement, ensuring the preview token is fully replaced by the actual pasted content.

This issue is particularly important for users typing CJK characters, since the incorrect truncation could leak part of the paste preview token into the submitted prompt, resulting in a polluted prompt.

How did you verify your code works?

Tested locally with bun dev ..

Reproduction steps:

  1. Enter Chinese text in the prompt.
  2. Paste multi-line content so [Pasted ~N lines] appears.
  3. Submit the prompt.

Before the fix, part of the preview token could appear in the submitted prompt.
After the fix, the preview is correctly replaced with the pasted content.

Tested with:

  • ASCII input
  • Chinese input

Screenshots / recordings

TUI after the fix:

  • Pasted multi-line content is previewed correctly in the input area.
  • After sending, the submitted prompt no longer contains leaked [Pasted ~N lines] fragments when the input includes CJK characters.
  • Verified with Chinese input and multi-line paste in the TUI.
image image

Checklist

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

changchinlan, CodingOX, willyliu-17, and KiruyaMomochi reacted with thumbs up emoji
All reactions
  • 👍 4 reactions
@AbigailJixiangyuyu
fix(tui): correct pasted preview replacement for CJK and multi-width …
0e023b5
…characters
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Mar 11, 2026
@github-actions

github-actions Bot commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AbigailJixiangyuyu AbigailJixiangyuyu changed the title fix(tui): correct pasted preview replacement for CJK and multi-width … fix(tui): correct pasted preview replacement for CJK and multi-width characters Mar 11, 2026
@changchinlan changchinlan mentioned this pull request Mar 13, 2026
Paste preview indicator "[Pasted ~N lines]" incorrectly included in submitted input #11143
Closed
@getbug

getbug commented Mar 13, 2026

Copy link
Copy Markdown

there's still a problem when using your commit codes, when input chinese, you can forcus the cursor to a gap between two words, is easy when using mouse, not left or right buttun。then "[" will be included in submitted input

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AbigailJixiangyuyu

AbigailJixiangyuyu commented Mar 13, 2026

Copy link
Copy Markdown
Contributor Author

there's still a problem when using your commit codes, when input chinese, you can forcus the cursor to a gap between two words, is easy when using mouse, not left or right buttun。then "[" will be included in submitted input

Thanks for testing this.

I’m not sure I fully understand the exact reproduction steps yet.

Could you provide a more detailed step-by-step reproduction example?

A short screen recording or before/after example would also help a lot.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@getbug

getbug commented Mar 14, 2026

Copy link
Copy Markdown

there's still a problem when using your commit codes, when input chinese, you can forcus the cursor to a gap between two words, is easy when using mouse, not left or right buttun。then "[" will be included in submitted input

Thanks for testing this.

I’m not sure I fully understand the exact reproduction steps yet.

Could you provide a more detailed step-by-step reproduction example?

A short screen recording or before/after example would also help a lot.

看你的昵称应该是中国人,我就用中文来描述现象吧,这边因为信息安全原因没法发图片,我用文字描述一下步骤吧
1、在输入框输入“快捷键测试用例”
2、用鼠标将光标点击到“键”、“测”之间,此时光标会选中“键”的右半边,“测”的左半边
3、粘贴几行文字,在“键”、“测”之间就插入了“[Pasted ~10 lines”
4、回车提交
5、在会话框,看到显示的文字是 “快捷键[....测试用例” (其中...是粘贴的多行内容),可看到展示的内容多了个[

willyliu-17 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Mar 14, 2026
📊 Bản tin hàng ngày công cụ AI CLI 2026-03-14 compasify/agents-radar#40
Open
@AbigailJixiangyuyu

AbigailJixiangyuyu commented Mar 16, 2026

Copy link
Copy Markdown
Contributor Author

there's still a problem when using your commit codes, when input chinese, you can forcus the cursor to a gap between two words, is easy when using mouse, not left or right buttun。then "[" will be included in submitted input

Thanks for testing this.
I’m not sure I fully understand the exact reproduction steps yet.
Could you provide a more detailed step-by-step reproduction example?
A short screen recording or before/after example would also help a lot.

看你的昵称应该是中国人,我就用中文来描述现象吧,这边因为信息安全原因没法发图片,我用文字描述一下步骤吧 1、在输入框输入“快捷键测试用例” 2、用鼠标将光标点击到“键”、“测”之间,此时光标会选中“键”的右半边,“测”的左半边 3、粘贴几行文字,在“键”、“测”之间就插入了“[Pasted ~10 lines” 4、回车提交 5、在会话框,看到显示的文字是 “快捷键[....测试用例” (其中...是粘贴的多行内容),可看到展示的内容多了个[

This issue is reproducible in opencode, but the root cause appears to be lower-level in @opentui/core rather than in opencode's prompt logic.
TextareaRenderable seems to allow the cursor to land on an invalid visual column inside a double-width character (for example CJK characters), instead of snapping to a valid character boundary. Once that happens, higher-level logic in opencode receives an invalid visualCursor.offset, which then causes downstream misalignment in insertText, extmark ranges, and placeholder replacement.
So while opencode can add local workarounds, the proper fix likely belongs in the opentui repository, specifically in TextareaRenderable cursor movement / mouse hit-testing for wide characters.

heimoshuiyu reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Mar 17, 2026
feat(tui): CJK-aware word boundary navigation via Intl.Segmenter #17959
Closed
fix(bug) paste image #18361
Closed
@xiejiati xiejiati mentioned this pull request Mar 22, 2026
[FEATURE]: CJK-aware word boundary navigation in TUI textarea #18604
Closed
1 task done
@getbug

getbug commented Mar 28, 2026

Copy link
Copy Markdown

i was wondering when will your commits merge into dev??? it fixed the bug mostly

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Apr 4, 2026
fix(tui): reconstruct pasted prompt text after wide characters #20987
Closed
3 of 6 tasks
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
@github-actions github-actions Bot mentioned this pull request Apr 23, 2026
fix(prompt): use display-width coordinates for extmark positions to handle CJK input correctly #24037
Closed
3 tasks done
@AbigailJixiangyuyu AbigailJixiangyuyu closed this Apr 27, 2026
@AbigailJixiangyuyu
AbigailJixiangyuyu deleted the fix/paste-preview-cjk-17032 branch April 27, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Pasted ~N lines] is partially submitted when prompt contains CJK or other multi-width characters

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@AbigailJixiangyuyu @getbug
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.