Skip to content

fix(tui): preserve skill picker text input on selection - #1028

Open
HaleTom wants to merge 5 commits into
XiaomiMiMo:mainfrom
HaleTom:fix-skill-picker
Open

HaleTom wants to merge 5 commits into
XiaomiMiMo:mainfrom
HaleTom:fix-skill-picker

Conversation

@HaleTom

@HaleTom HaleTom commented Jun 18, 2026

Copy link
Copy Markdown

Ported from anomalyco/opencode#27632

Issue for this PR

Closes /skill slash command wipes existing input text instead of preserving it #27578
Closes fix(tui): insert selected skill into prompt #27160
Closes fix: append skills to the prompt instead of replacing #18756
Closes Selecting a skill from the dropdown completely replaces the prompt instead of "appending" to it #18755

Type of change

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

What does this PR do?

When selecting a skill from the TUI skill picker, the skill name is now inserted at the current cursor position using input.insertText() instead of replacing the entire prompt with input.setText(). This preserves any text the user has already typed in the prompt box.

Previously, typing a question then selecting a skill would destructively wipe the entire prompt — a frustrating UX reported multiple times.

Whitespace note (re: [review on fix(tui): insert selected skill into prompt #27160](anomalyco/opencode#27160 (review)))

insertText does not trim surrounding whitespace. This is consistent with every other insertText call in the same file — file attachments, paste, and history restore all append " " unconditionally. It's a pre-existing cosmetic pattern, not specific to this fix.

Replaces fix(tui): insert skill name without wiping existing prompt text #27584

The previous PR ([fix(tui): insert skill name without wiping existing prompt text #27584](anomalyco/opencode#27584)) was closed because a close/reopen trick used to force a diff refresh after a rebase left the PR permanently locked — GitHub refused to reopen it ("no new commits on the branch"). This replacement PR has the same change on the same branch.

Credits

This fix borrows from and improves upon two prior community PRs:

How did you verify your code works?

Manually verified the logic by inspecting the existing patterns in the codebase:

  • input.insertText() is already used extensively throughout this file (history restore, paste, file attachments, PromptAppend event handler)
  • syncExtmarksWithPromptParts() is already called in onContentChange and during IME submission sync — consistent usage
  • setStore("prompt", "input", rawText) matches how onContentChange syncs state

Screenshots / recordings

N/A — 3-line change affecting only the skill picker onSelect handler.

Checklist

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

Note on force pushes to main

This PR was originally raised as #592 but was auto-closed when the main branch was force-pushed (see #760). Force-pushing to a shared branch breaks PR reopenability and orphans review comments.

HaleTom added 5 commits June 18, 2026 19:21
When selecting a skill from the TUI skill picker, the skill name is now
inserted at the cursor position using input.insertText() instead of
replacing the entire prompt with input.setText().

Previously, typing a question then selecting a skill would destructively
wipe the entire prompt.

Closes: #27578
Closes: #27160
Closes: #18756
Closes: #18755
…rompt text

Added a regression test at packages/opencode/test/cli/tui/prompt-skill-select.test.ts
that exercises the skill picker onSelect handler:

- 'inserts skill name without wiping existing prompt text' — sets up an input with
  pre-existing text, simulates onSelect with a skill name, asserts the result is
  'some existing text/test-skill ' (append via insertText rather than replacement
  via setText)
- 'inserts skill name into empty prompt' — same assertion on an empty initial text

Both pass with the current insertText-based logic and would fail with the old
setText-based logic (which replaced the full input content).

Addresses review comment: anomalyco/opencode#27632 (comment)
Updated the mock insertText to track cursorOffset and insert at cursor
position rather than always appending. Added two new test cases:
- 'inserts skill name at cursor position when cursor is at start' — verifies
  skill prefix is prepended when cursor is at position 0
- 'inserts skill name at cursor position mid-text' — verifies insertion at
  arbitrary cursor position

Addresses review comment: anomalyco/opencode#27632 (comment)
Address review feedback: guard against undefined or destroyed input
before calling insertText in the skill picker onSelect handler.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant