nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

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

Open addyCooks opened this issue 2 months ago • 2 comments

Description

When typed text exactly matches exactly one available slash command (e.g. /model), the completion effect opens the menu with that single match highlighted correct, non-stale state, not a race. Pressing Enter in that state always hits the "select completion" branch: it re-applies text that's already correct and closes the menu, but never falls through to submit. The command silently requires a second Enter to actually run.

Related but distinct from #1327: #1327 is a stale-closure race Enter pressed instantly after typing a non-matching fragment (e.g. /xy) submits the raw fragment as a chat message because showCompletions is read from outdated state. This issue is the opposite failure mode and not timing-dependent: with a fully-settled, exact match, Enter still doesn't submit — it just closes the menu and no-ops. Fixing #1327's stale-closure race (gating Enter on the memoized commandCompletions) does not fix this, since the "select completion" branch has no exact-match check regardless of whether the state it reads is fresh or stale.

Parent: #907

Steps to Reproduce

  1. Type a slash command name in full and exactly, character by character (e.g. /model), so the completion menu settles on it as the sole highlighted match.
  2. Wait for the menu to render (no race any normal pause is fine).
  3. Press Enter once.

Expected Behavior

Enter submits the command immediately, since the typed text is already an exact, unambiguous match — there's nothing left to "select."

Actual Behavior

The completion menu closes but the command is not run: /model is left sitting in the composer, unsent, and the app state (welcome screen, session, etc.) is unchanged. A second Enter is required to actually submit it. This is the same race this session's own test-recording scripts have routed around all along with a blind double-Enter, for every slash command driven (/checkpoint load, /rename, /settings mcp, etc.) — it's a general, live UX defect, not specific to one command.

Recording

Image

Root Cause

source/components/user-input.tsx:1029-1040:

// Handle Enter to select completion
if (
	key.return &&
	!key.shift &&
	showCompletions &&
	completions.length > 0 &&
	selectedCompletionIndex >= 0
) {
	const selected = completions[selectedCompletionIndex];
	const completedText = `/${selected.name}`;
	completionJustSelectedRef.current = true;
	setInputState({
		displayValue: completedText,
		placeholderContent: {},
	});
	setShowCompletions(false);
	setSelectedCompletionIndex(-1);
	// ... returns without submitting

This branch fires unconditionally whenever the menu is open with a highlighted item, even when completedText is byte-identical to input there is no check for "the selection is a no-op," so it can never fall through to submit.

Suggested Fix

If completedText === input, fall through to the submit path instead of re-selecting an already-selected, already-typed value.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate (checked specifically against #1327 see Description)
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs on the latest main

addyCooks avatar Sep 22 '26 08:09 addyCooks

Hi @akramcodez, I'm interested in this one could you assign this to me?

addyCooks avatar Sep 22 '26 08:09 addyCooks

Picking this up - a fix will follow shortly.

awhite0030 avatar Sep 22 '26 10:09 awhite0030