Skip to content

fix(tui): select the completion when Enter follows a command fragment - #1353

Open
addyCooks wants to merge 1 commit into
Nano-Collective:mainfrom
addyCooks:fix/enter-stale-completions-1327
Open

addyCooks wants to merge 1 commit into
Nano-Collective:mainfrom
addyCooks:fix/enter-stale-completions-1327

Conversation

@addyCooks

@addyCooks addyCooks commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Closes #1327

Description

Pressing Enter immediately after typing a slash-command fragment submitted the raw fragment instead of selecting a completion.

Cause. The completion menu is opened by an effect that runs a commit after the keystroke that changed input. Ink re-subscribes the useInput handler in the same passive-effect flush, so for a turn or two the live handler sees the new input but showCompletions still false. Enter in that window skipped the "select the completion" branch and fell through to handleSubmit. Instrumenting the handler confirmed it: Enter one or two event-loop turns after the fragment rendered saw input="/test-h", showCompletions=false, one memoized match, and submitted /test-h.

Why not gate purely on commandCompletions (the issue's suggestion): right after a completion is selected, the completed command still has matches, so a memo-only gate would re-select on every Enter and never submit.

Fix (source/components/user-input.tsx):

  • The Enter gate keeps using the menu state when it says the menu is open (so a menu re-opened with Tab still works), and only when that state says closed falls back to the memoized completions the effect is about to show.
  • The fallback applies the same suppression the effect uses closed for this exact input, or recalled from history now shared as isMenuSuppressedFor so the two cannot drift.
  • Selecting a completion now marks that input closed, like Escape already did, so Enter on a selected command submits it.

Recording

B06-FIXED-enter-selects-completion

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Checklist

  • If this was for an open issue, I was assigned to it
  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed) no documented behaviour changes
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging

The completion menu opens in an effect a commit after the keystroke that changed the input, so an Enter landing in between saw showCompletions still false and submitted the raw fragment. When the menu state says closed, the Enter gate now falls back to the memoized completions the effect is about to show, under the same suppression rules the effect uses (now shared). Selecting a completion marks that input closed, like Escape, so Enter still submits a command once it has been selected. Closes Nano-Collective#1327.
@github-actions

Copy link
Copy Markdown
Contributor

nc-review: nothing to raise

@addyCooks — nothing to raise from the automated review.

Fixes the Enter-on-stale-completions race from #1327 by gating Enter on the memoized commandCompletions when the menu state hasn't caught up yet, while preserving Escape-suppression and the 'submit once a completion is selected' behavior via a shared isMenuSuppressedFor helper. The diff is small, focused, and accompanied by a sweep regression test plus a follow-up test for the select-then-submit path, and a correctly scoped changeset.


🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional

Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with /re-review.

@github-actions github-actions Bot added the agent:clean nc-review had nothing to raise label Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:clean nc-review had nothing to raise area:tui Terminal UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Enter pressed the instant a / menu opens submits raw text instead of selecting

1 participant