Skip to content

feat(cosh): add large paste placeholder and fix placeholder id reset on esc cancel#312

Open
kongld-mq wants to merge 5 commits into
alibaba:mainfrom
kongld-mq:feat/cosh/large_paste_placeholder
Open

feat(cosh): add large paste placeholder and fix placeholder id reset on esc cancel#312
kongld-mq wants to merge 5 commits into
alibaba:mainfrom
kongld-mq:feat/cosh/large_paste_placeholder

Conversation

@kongld-mq
Copy link
Copy Markdown
Collaborator

@kongld-mq kongld-mq commented Apr 23, 2026

Description

feat(cosh): add large paste placeholder and fix placeholder id reset on esc cancel

  • Create placeholder for pastes >1000 chars or >10 lines instead of full content
  • Support sequential IDs for multiple pastes of same size with reuse mechanism
  • Atomically delete placeholder on Backspace
  • Expand placeholder to full content on submit
  • Use pasteWorkaround check for macOS Enter-fix to prevent double-submit
  • Handle clipboard errors with debugLogger instead of console.error
  • Clear pendingPastes and activePlaceholderIds on double ESC to reset ID counter
  • Add 9 new test cases covering placeholder creation, expansion, deletion, reuse, and ESC reset
  • Fix enter-submit on macOS: only apply recentPasteTime protection when
    pasteWorkaround is enabled (Windows or Node < 20). On macOS/Linux with
    modern Node, bracketed paste markers work reliably so the protection is
    unnecessary and caused the first Enter after paste to be ignored.

Related Issue

closes #

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional change)
  • Performance improvement
  • CI/CD or build changes

Scope

  • cosh (copilot-shell)
  • sec-core (agent-sec-core)
  • skill (os-skills)
  • sight (agentsight)
  • Multiple / Project-wide

Checklist

  • I have read the Contributing Guide
  • My code follows the project's code style
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the documentation accordingly
  • For cosh: Lint passes, type check passes, and tests pass
  • For sec-core (Rust): cargo clippy -- -D warnings and cargo fmt --check pass
  • For sec-core (Python): Ruff format and pytest pass
  • For skill: Skill directory structure is valid and shell scripts pass syntax check
  • For sight: cargo clippy -- -D warnings and cargo fmt --check pass
  • Lock files are up to date (package-lock.json / Cargo.lock)

Testing

After generating the test text, paste it into the input box

large text test(>1000 chars)

python3 -c "print('A' * 1500)"

Multi-line test (>10 lines)

for i in {1..15}; do echo "Line $i"; done

Small text test(<1000 chars)

python3 -c "print('A' * 500)"

Additional Notes

大文本粘贴 粘贴 1500 字符 显示 [Pasted Content 1500 chars]
多行粘贴 粘贴 15 行 显示 [Pasted Content XX chars]
小文本粘贴 粘贴 500 字符 正常显示完整文本
多次粘贴 连续粘贴两次 1001 字符 第二次显示 #2
Backspace 粘贴后按 Backspace 整体删除占位符

…on esc cancel

- Create placeholder for pastes >1000 chars or >10 lines instead of full content
- Support sequential IDs for multiple pastes of same size with reuse mechanism
- Atomically delete placeholder on Backspace
- Expand placeholder to full content on submit
- Use pasteWorkaround check for macOS Enter-fix to prevent double-submit
- Handle clipboard errors with debugLogger instead of console.error
- Clear pendingPastes and activePlaceholderIds on double ESC to reset ID counter
- Add 9 new test cases covering placeholder creation, expansion, deletion, reuse, and ESC reset

Signed-off-by: konglidong <kld02270359@alibaba-inc.com>
@gemini-code-assist
Copy link
Copy Markdown

Important

Installation incomplete: to start using Gemini Code Assist, please ask the organization owner(s) to visit the Gemini Code Assist Admin Console and sign the Terms of Services.

@github-actions github-actions Bot added the component:cosh src/copilot-shell/ label Apr 23, 2026
Copy link
Copy Markdown
Collaborator

@samchu-zsl samchu-zsl left a comment

Choose a reason for hiding this comment

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

Summary

非常棒的功能扩展 🎉 —— 大粘贴占位符、ID 复用、ESC 重置整体思路清晰,测试用例也覆盖了主要正向路径。以下留下 4 条具体改动建议,按建议处理后整体可以合入:

🟡 Major(建议修复)

  • UTF-16 vs code-point 偏移混用InputPrompt.tsx L878-L892):backspace 删除占位符的路径里,buffer.lines[i].lengthtext.slice 走 UTF-16,而 buffer.cursor 的 col 和 replaceRangeByOffset 走 code-point,混用后只要用户在占位符前输入了 emoji 等非 BMP 字符就会错位。
  • 占位符被部分删除后原文静默丢失InputPrompt.tsx L867-L907):当前仅匹配「光标恰好在占位符尾」,若用户按 ← 进入占位符内部或从下一行回退再 backspace,占位符字符串被逐字破坏,而 pendingPastes 仍持有完整 key,提交时正则匹配失败,用户拿到残缺占位符而非原文。
  • recentPasteTime gating 语义变化缺测试InputPrompt.tsx L798):加了 pasteWorkaround && 后,原来的 paste-auto-submission 保护测试因为默认 pasteWorkaround=false,实际已经不再走到保护分支了;建议补一条 pasteWorkaround=true 下的回归测试。

ℹ️ Minor

  • 占位符文案硬编码(InputPrompt.tsx L179):同文件已经 import { t },建议走 i18n。

感谢贡献!

Comment thread src/copilot-shell/packages/cli/src/ui/components/InputPrompt.tsx Outdated
Comment thread src/copilot-shell/packages/cli/src/ui/components/InputPrompt.tsx Outdated
Comment thread src/copilot-shell/packages/cli/src/ui/components/InputPrompt.tsx
Comment thread src/copilot-shell/packages/cli/src/ui/components/InputPrompt.tsx Outdated
kongld-mq added 4 commits May 11, 2026 13:21
…laceholder backspace deletion logic

Signed-off-by: konglidong <kld02270359@alibaba-inc.com>
…loss when backspace is pressed inside placeholder range

Signed-off-by: konglidong <kld02270359@alibaba-inc.com>
…bmission protection

Signed-off-by: konglidong <kld02270359@alibaba-inc.com>
Review issue alibaba#4: Add i18n support for placeholder display text
- Use t('input.paste.placeholder', { charCount }) for localized text
- Add keys in locales/en.js and locales/zh.js
- Placeholder marker uses Unicode private area char (\uE000)

Backspace deletion fixes:
- Fix sequence number disorder: sync pendingPastes with actual markers
  in buffer, cleanup orphan entries and release their IDs
- Fix emoji/non-BMP char deletion error: use code-point semantics
  (toCodePoints + cpSlice) instead of UTF-16 indexing
- Cursor movement correctly handles placeholder boundaries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:cosh src/copilot-shell/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants