mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-03 08:24:10 -07:00
fix(core): only show list suggestion if the partial input is empty (#25821)
This commit is contained in:
@@ -513,6 +513,70 @@ describe('useSlashCompletion', () => {
|
|||||||
unmountResume();
|
unmountResume();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should NOT suggest the auto-list command when typing a non-matching partial after /chat', async () => {
|
||||||
|
const slashCommands = [
|
||||||
|
createTestCommand({
|
||||||
|
name: 'chat',
|
||||||
|
description: 'Manage chat history',
|
||||||
|
subCommands: [
|
||||||
|
createTestCommand({ name: 'list', description: 'List chats' }),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
|
const { result, unmount } = await renderHook(() =>
|
||||||
|
useTestHarnessForSlashCompletion(
|
||||||
|
true,
|
||||||
|
'/chat x', // 'x' does not match 'list'
|
||||||
|
slashCommands,
|
||||||
|
mockCommandContext,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await resolveMatch();
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
// It should NOT have the 'auto' section 'list' suggestion
|
||||||
|
const autoSuggestion = result.current.suggestions.find(
|
||||||
|
(s) => s.sectionTitle === 'auto',
|
||||||
|
);
|
||||||
|
expect(autoSuggestion).toBeUndefined();
|
||||||
|
});
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should STILL suggest the auto-list command when typing a matching partial after /chat', async () => {
|
||||||
|
const slashCommands = [
|
||||||
|
createTestCommand({
|
||||||
|
name: 'chat',
|
||||||
|
description: 'Manage chat history',
|
||||||
|
subCommands: [
|
||||||
|
createTestCommand({ name: 'list', description: 'List chats' }),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
|
const { result, unmount } = await renderHook(() =>
|
||||||
|
useTestHarnessForSlashCompletion(
|
||||||
|
true,
|
||||||
|
'/chat l', // 'l' matches 'list'
|
||||||
|
slashCommands,
|
||||||
|
mockCommandContext,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await resolveMatch();
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
const autoSuggestion = result.current.suggestions.find(
|
||||||
|
(s) => s.sectionTitle === 'auto',
|
||||||
|
);
|
||||||
|
expect(autoSuggestion).toBeDefined();
|
||||||
|
expect(autoSuggestion?.label).toBe('list');
|
||||||
|
});
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
it('should sort exact altName matches to the top', async () => {
|
it('should sort exact altName matches to the top', async () => {
|
||||||
const slashCommands = [
|
const slashCommands = [
|
||||||
createTestCommand({
|
createTestCommand({
|
||||||
|
|||||||
@@ -338,17 +338,23 @@ function useCommandSuggestions(
|
|||||||
|
|
||||||
if (isTopLevelChatOrResumeContext) {
|
if (isTopLevelChatOrResumeContext) {
|
||||||
const canonicalParentName = leafCommand.name;
|
const canonicalParentName = leafCommand.name;
|
||||||
const autoSectionSuggestion: Suggestion = {
|
const autoLabel = 'list';
|
||||||
label: 'list',
|
if (
|
||||||
value: 'list',
|
partial === '' ||
|
||||||
insertValue: canonicalParentName,
|
autoLabel.toLowerCase().startsWith(partial.toLowerCase())
|
||||||
description: 'Browse auto-saved chats',
|
) {
|
||||||
commandKind: CommandKind.BUILT_IN,
|
const autoSectionSuggestion: Suggestion = {
|
||||||
sectionTitle: 'auto',
|
label: autoLabel,
|
||||||
submitValue: `/${canonicalParentName}`,
|
value: autoLabel,
|
||||||
};
|
insertValue: canonicalParentName,
|
||||||
setSuggestions([autoSectionSuggestion, ...finalSuggestions]);
|
description: 'Browse auto-saved chats',
|
||||||
return;
|
commandKind: CommandKind.BUILT_IN,
|
||||||
|
sectionTitle: 'auto',
|
||||||
|
submitValue: `/${canonicalParentName}`,
|
||||||
|
};
|
||||||
|
setSuggestions([autoSectionSuggestion, ...finalSuggestions]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setSuggestions(finalSuggestions);
|
setSuggestions(finalSuggestions);
|
||||||
|
|||||||
Reference in New Issue
Block a user