Skip to content

Commit

Permalink
Replace command filter from startsWith to includes (#1824)
Browse files Browse the repository at this point in the history
- Sort commands based on the start index of the included string
  • Loading branch information
1 parent c981730 commit cf5d5ad
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions frontend/src/components/chat/MessageComposer/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,15 @@ const Input = forwardRef<InputMethods, Props>(
}
}, [selectedCommand, onChange]);

const filteredCommands = commands.filter((command) =>
command.id.toLowerCase().startsWith(commandInput.toLowerCase().slice(1))
);
const normalizedInput = commandInput.toLowerCase().slice(1);

const filteredCommands = commands
.filter((command) => command.id.toLowerCase().includes(normalizedInput))
.sort((a, b) => {
const indexA = a.id.toLowerCase().indexOf(normalizedInput);
const indexB = b.id.toLowerCase().indexOf(normalizedInput);
return indexA - indexB;
});

useEffect(() => {
const textarea = contentEditableRef.current;
Expand Down

0 comments on commit cf5d5ad

Please sign in to comment.