Merge pull request #47 from continuedev/slash-only-start

Only trigger slash commands when slash is the very first character
This commit is contained in:
Nate Sesti 2025-07-16 09:50:31 -07:00 • committed by GitHub
commit e1d6f5d802
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 15 deletions

View file

@ -18,7 +18,8 @@ export async function handleSlashCommands(
newInput?: string;
clear?: boolean;
} | null> {
if (input.startsWith("/")) {
// Only trigger slash commands if slash is the very first character
if (input.startsWith("/") && input.trim().startsWith("/")) {
const [command, ...args] = input.slice(1).split(" ");
switch (command) {
case "help":

View file

@ -80,20 +80,24 @@ const UserInput: React.FC<UserInputProps> = ({
// Update slash command UI state based on input
const updateSlashCommandState = (text: string, cursor: number) => {
// Check if we're in a slash command context
const beforeCursor = text.slice(0, cursor);
const lastSlashIndex = beforeCursor.lastIndexOf("/");
if (lastSlashIndex !== -1) {
// Check if there's any whitespace between the last slash and cursor
const afterSlash = beforeCursor.slice(lastSlashIndex + 1);
if (!afterSlash.includes(" ") && !afterSlash.includes("\n")) {
// We're in a slash command context
setShowSlashCommands(true);
setSlashCommandFilter(afterSlash);
setSelectedCommandIndex(0);
setShowFileSearch(false);
// Only show slash commands if slash is the very first character
if (text.trimStart().startsWith("/")) {
const trimmedText = text.trimStart();
const beforeCursor = trimmedText.slice(0, cursor - (text.length - trimmedText.length));
// Only show if cursor is after the slash and before any whitespace
if (beforeCursor.length > 0 && beforeCursor.startsWith("/")) {
const afterSlash = beforeCursor.slice(1);
if (!afterSlash.includes(" ") && !afterSlash.includes("\n")) {
// We're in a slash command context
setShowSlashCommands(true);
setSlashCommandFilter(afterSlash);
setSelectedCommandIndex(0);
setShowFileSearch(false);
} else {
setShowSlashCommands(false);
}
} else {
setShowSlashCommands(false);
}