Skip to content

fix(input): submit a slash command typed in full on the first Enter - #1502

Merged
akramcodez merged 3 commits into
Nano-Collective:mainfrom
addyCooks:fix/enter-submits-exact-command-1431
Oct 1, 2026
Merged

akramcodez merged 3 commits into
Nano-Collective:mainfrom
addyCooks:fix/enter-submits-exact-command-1431

Conversation

@addyCooks

@addyCooks addyCooks commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1431 (part of #907)

Description

When the typed text exactly matches a slash command, the completion menu opens with that command highlighted. Pressing Enter then took the "select completion" branch, which re-applied text that was already in the composer, closed the menu and returned without ever reaching the submit path. Every command needed a second Enter to run.

This isn't timing-dependent, so it's separate from #1327 (the stale-closure race where Enter submits a non-matching fragment). Gating Enter on fresh state wouldn't fix it, because that branch never checked whether the selection was a no-op.

The selection branch now does nothing when the highlighted completion already equals the input, so Enter falls through to the existing submit path, which also resets the completion state and closes the menu:

const completedText = `/${selected.name}`;
if (completedText !== input) {
    // ... select the completion and return
}
// otherwise fall through to submit

A partly typed command (/mod) is untouched: it still completes to /model on Enter without submitting, which the second new test guards.

File Change
source/components/user-input.tsx Skip the completion selection when it is already what was typed, so Enter submits
source/components/user-input.spec.tsx Exact command submits on the first Enter; a partly typed command still completes

Recording

B20-FIXED-exact-command-enter

Type of Change

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

Changeset

  • Added a changeset (.changeset/enter-submits-exact-command.md, patch)

Testing

  • New test types /test-help in full, waits for the menu, presses Enter once and asserts the command is submitted. It fails on main and passes with the fix.
  • New test types /test-he, presses Enter and asserts the input becomes /test-help with nothing submitted. It passes on both, guarding the existing completion behaviour.
  • Existing Enter/completion tests pass ("Enter selects the highlighted completion", "typing a space after a command", "completion menu dismissal", "arrow key navigation")
  • tsc, Biome format and lint clean
  • pnpm test:knip could not run locally (out of memory); nothing new is exported or imported, so CI will run it first

Note

UserInput submits slash commands immediately while busy is timing-sensitive: it presses Enter the moment /help renders, before the input handler has picked up the new value, so it can fail on a loaded machine with or without this change. A short wait before Enter makes it stable. Happy to send that as a follow-up.

Checklist

  • I was assigned to the issue
  • Code follows project style guidelines
  • Self-review completed
  • No breaking changes

When the typed text exactly matches a command, the completion menu opens
with that command highlighted. Enter then took the "select completion"
branch, which re-applied text that was already in the composer, closed the
menu and returned, so every command needed a second Enter to run.

Skip the selection when the highlighted completion is already what was
typed and fall through to the submit path. Partly typed commands still
complete on Enter as before.

Closes Nano-Collective#1431
@github-actions

Copy link
Copy Markdown
Contributor

nc-review: comments — 1 nit

@addyCooks — a few things worth a look, none blocking.

The change correctly fixes the bug: when the typed text exactly matches a slash command, Enter used to fall into the 'select completion' branch, re-apply the same text, and close the menu without submitting. Adding a completedText !== input guard so that branch no-ops in the no-op case lets execution fall through to handleSubmit(). The two new tests are well-scoped — one reproduces the bug (exact-match submits on first Enter) and the other guards the existing partial-completion behaviour — and input is correctly in scope from the useInputState() destructure above. Ready to merge modulo one nit about the wording of the changeset bullet.

⚪ nit · changeset · .changeset/enter-submits-exact-command.md

The bullet opens by asserting past behaviour in the present tense ("the completion menu opened with it highlighted, and Enter 'selected' it") rather than describing the user-facing impact in the before/after voice used elsewhere in CHANGELOG.md. Rewriting to lead with the user-visible change — e.g. "Pressing Enter on a fully typed slash command now runs it on the first press instead of needing a second Enter to dismiss the completion menu." — would match house style more closely. Not blocking; the changeset is present, names the package, has the right bump type, and is honest about the closed issue.


🔴 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:comments nc-review left non-blocking findings label Sep 26, 2026
@addyCooks

Copy link
Copy Markdown
Collaborator Author

Quick heads up: the red Semgrep Security Scan here isn't from this PR

It's flagging source/custom-commands/loader.ts:20 (detect-non-literal-regexp), which this PR doesn't touch. That line landed on main in 4002073, so any PR branched after it gets the same blocking finding. The phrase is already escaped, so it's a false positive. Semgrep just can't see the escaping.

The fix is in #1503. It swaps the RegExp for a plain indexOf scan with the same behaviour, so the finding goes away without a suppression. Once it merges I'll rebase this PR and the check should go green. The rest of the checks here pass

nc-review: match house style by leading with the before/after impact
instead of narrating the old behaviour first.
@akramcodez
akramcodez merged commit 5912df5 into Nano-Collective:main Oct 1, 2026
16 checks passed
@akramcodez

Copy link
Copy Markdown
Member

As always great work @addyCooks

@addyCooks

Copy link
Copy Markdown
Collaborator Author

Thanks @akramcodez : )

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

Labels

agent:comments nc-review left non-blocking findings area:tui Terminal UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Enter on an exact, unambiguous slash-command match closes the completion menu instead of submitting

2 participants