Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/cli/src/ui/components/InputPrompt.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,25 @@ describe('InputPrompt', () => {
});

describe('command search (Ctrl+R when not in shell)', () => {
it('passes newest-first user history to command search', async () => {
props.shellModeActive = false;
props.userMessages = ['oldest', 'middle', 'newest'];

const { unmount } = renderWithProviders(<InputPrompt {...props} />);
await wait();

const commandSearchCall =
mockedUseReverseSearchCompletion.mock.calls.find(
([, history]) =>
Array.isArray(history) &&
history.length === 3 &&
history.includes('newest'),
);

expect(commandSearchCall?.[1]).toEqual(['newest', 'middle', 'oldest']);
unmount();
});

it('enters command search on Ctrl+R and shows suggestions', async () => {
props.shellModeActive = false;

Expand Down
9 changes: 7 additions & 2 deletions packages/cli/src/ui/components/InputPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import type React from 'react';
import { useCallback, useEffect, useState, useRef } from 'react';
import { useCallback, useEffect, useMemo, useState, useRef } from 'react';
import { Box, Text } from 'ink';
import { SuggestionsDisplay, MAX_WIDTH } from './SuggestionsDisplay.js';
import { theme } from '../semantic-colors.js';
Expand Down Expand Up @@ -213,9 +213,14 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
reverseSearchActive,
);

const commandSearchHistory = useMemo(
() => [...userMessages].reverse(),
[userMessages],
);

const commandSearchCompletion = useReverseSearchCompletion(
buffer,
userMessages,
commandSearchHistory,
commandSearchActive,
);

Expand Down
Loading