fix: restrict token deletion to agents, subcommands, and tools#305888
fix: restrict token deletion to agents, subcommands, and tools#305888swematheus wants to merge 6 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts chat input backspace behavior so that only agent, agent-subcommand, and tool parts are treated as atomic “tokens” for deletion, preventing standalone slash commands/prompts from being deleted as a whole.
Changes:
- Introduces an
isDeletableTokenhelper to centralize which parsed parts should be deleted atomically. - Updates
ChatTokenDeleterto use the helper, excluding slash command/prompt parts from token deletion behavior.
| const previousParsedValue = parser.parseChatRequestWithReferences(getDynamicVariablesForWidget(this.widget), getSelectedToolAndToolSetsForWidget(this.widget), previousInputValue, this.widget.location, { selectedAgent: previousSelectedAgent, mode: this.widget.input.currentModeKind, attachmentCapabilities }); | ||
|
|
||
| // For dynamic variables, this has to happen in ChatDynamicVariableModel with the other bookkeeping | ||
| const deletableTokens = previousParsedValue.parts.filter(p => p instanceof ChatRequestAgentPart || p instanceof ChatRequestAgentSubcommandPart || p instanceof ChatRequestSlashCommandPart || p instanceof ChatRequestSlashPromptPart || p instanceof ChatRequestToolPart); | ||
| const deletableTokens = previousParsedValue.parts.filter(isDeletableToken); | ||
| deletableTokens.forEach(token => { |
There was a problem hiding this comment.
The token-deletion behavior is being changed (slash commands/prompts are no longer treated as atomic tokens for backspace), but there’s no automated coverage to prevent regressions. Consider adding a browser unit test that instantiates a chat input editor and verifies: (1) backspace inside /con deletes a single character rather than removing the whole token, and (2) backspace over agent/subcommand/tool tokens still deletes the whole token.
This PR fixes the issue reported in #305366 by extracting the token deletion filtering logic into a new helper function
isDeletableToken. This function identifies deletable tokens as ChatRequestAgentPart, ChatRequestAgentSubcommandPart, and ChatRequestToolPart, centralizing the logic for better maintainability and ensuring consistent behavior during chat input editing.Previously, slash commands were deleted as whole tokens, which could be disruptive, now they behave like regular text, deleting character by character.
To test: Run the project. Open a chat, type any commands starting with
/and press backspace. You'll see that now we delete char by char instead of the whole command.