From 3018b01460b9a90dd562f0cbae4a449440d0dbfa Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Fri, 21 Nov 2025 21:50:19 +0100 Subject: [PATCH] Fix slash command autocomplete Enter behavior When pressing Enter on a highlighted slash command suggestion (e.g., typing `/mod` with `/model` highlighted), the completion is now applied before submitting. Previously, the partial text was submitted instead of the selected command. Fixes #49 --- packages/coding-agent/CHANGELOG.md | 1 + packages/tui/src/components/editor.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index f348eca6..9bf59682 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -10,6 +10,7 @@ ### Fixed +- **Slash Command Autocomplete**: Fixed issue where pressing Enter on a highlighted slash command suggestion (e.g., typing `/mod` with `/model` highlighted) would submit the partial text instead of executing the selected command. Now Enter applies the completion and submits in one action. ([#49](https://github.com/badlogic/pi-mono/issues/49)) - **Model Matching Priority**: The `--models` flag now prioritizes exact matches over partial matches. Supports `provider/modelId` format (e.g., `openrouter/openai/gpt-5.1-codex`) for precise selection. Exact ID matches are tried before partial matching, so `--models gpt-5.1-codex` correctly selects `gpt-5.1-codex` instead of `openai/gpt-5.1-codex-mini`. - **Markdown Link Rendering**: Fixed links with identical text and href (e.g., `https://github.com/badlogic/pi-mono/pull/48/files`) being rendered twice. Now correctly compares raw text instead of styled text (which contains ANSI codes) when determining if link text matches href. diff --git a/packages/tui/src/components/editor.ts b/packages/tui/src/components/editor.ts index 65f35a90..515cc3ef 100644 --- a/packages/tui/src/components/editor.ts +++ b/packages/tui/src/components/editor.ts @@ -220,8 +220,22 @@ export class Editor implements Component { return; } - // If Enter was pressed on a slash command, cancel autocomplete and let it submit + // If Enter was pressed on a slash command, apply completion and submit if (data === "\r" && this.autocompletePrefix.startsWith("/")) { + const selected = this.autocompleteList.getSelectedItem(); + if (selected && this.autocompleteProvider) { + const result = this.autocompleteProvider.applyCompletion( + this.state.lines, + this.state.cursorLine, + this.state.cursorCol, + selected, + this.autocompletePrefix, + ); + + this.state.lines = result.lines; + this.state.cursorLine = result.cursorLine; + this.state.cursorCol = result.cursorCol; + } this.cancelAutocomplete(); // Don't return - fall through to submission logic }