Skip to content

fix: enable slash command chaining on any line in multiline input#12029

Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/slash-command-chaining-multiline
Draft

fix: enable slash command chaining on any line in multiline input#12029
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/slash-command-chaining-multiline

Conversation

@roomote-v0
Copy link
Copy Markdown
Contributor

@roomote-v0 roomote-v0 bot commented Mar 29, 2026

Related GitHub Issue

Closes: #12028

Description

This PR attempts to address Issue #12028. Feedback and guidance are welcome.

Previously, slash commands only worked on the first line of the textarea because the detection logic checked the entire text value (text.startsWith("/")) rather than the current line where the cursor sits.

Three targeted changes were made:

  1. shouldShowContextMenu() (context-mentions.ts): Extracts the current line from the text based on cursor position and checks if that line starts with / (instead of checking the full text).

  2. handleChange() (ChatTextArea.tsx): Same current-line extraction approach for slash command detection and search query building.

  3. insertMention() (context-mentions.ts): When isSlashCommand is true, replaces only the slash token on the current line (from line start to cursor) instead of replacing the entire text content. This preserves content on other lines.

Test Procedure

  • Updated existing tests in context-mentions.spec.ts to reflect the new per-line behavior
  • Added new multiline tests for:
    • Slash command detection on second/third lines via shouldShowContextMenu
    • Slash command insertion preserving other lines via insertMention
    • Edge cases (slash with space on non-first line, non-slash text on second line)
  • All 54 tests pass: cd webview-ui && npx vitest run src/utils/__tests__/context-mentions.spec.ts

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes.
  • Documentation Impact: No documentation updates are required.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

The backend slash command parsing (src/core/mentions/index.ts) already uses commandRegexGlobal which handles multiline text correctly, so no backend changes were needed.

Interactively review PR in Roo Code Cloud

Previously, slash commands only worked on the first line of the textarea.
This was because shouldShowContextMenu(), handleChange(), and
insertMention() all checked against the full text value rather than the
current line where the cursor is positioned.

Changes:
- shouldShowContextMenu: extract current line from cursor position and
  check if it starts with "/" instead of checking entire text
- ChatTextArea handleChange: same current-line extraction for slash
  command detection and query building
- insertMention: when isSlashCommand is true, replace only the slash
  token on the current line instead of the entire text content

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Slash Commands Chaining not working

1 participant