Skip to content

Commit

Permalink
fix(autocomplete): fix bug with nested path and single AC item
Browse files Browse the repository at this point in the history
  • Loading branch information
ctaylo21 committed Apr 18, 2020
1 parent ca04ed9 commit e66a821
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,23 @@ describe('autocomplete with tab', (): void => {
});

describe('cd', (): void => {
test('nested path with a single option', async (): Promise<void> => {
const { container, getByLabelText } = render(
<Terminal fileSystem={exampleFileSystem} />,
);

const input = getByLabelText('terminal-input') as HTMLInputElement;
await userEvent.type(input, 'cd home/user/');
await fireTabInput(input);

const autoCompleteContent = await findByLabelText(
container,
'autocomplete-preview',
);

expect(autoCompleteContent.innerHTML).toBe('');
expect(input.value).toEqual('cd home/user/test/');
});
test('tab press with single item should autofill it', async (): Promise<
void
> => {
Expand Down
8 changes: 7 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,17 @@ export class Terminal extends Component<TerminalProps, TerminalState> {
if (commandResult) {
// If only one autocomplete option is available, just use it
if (Object.keys(commandResult).length === 1) {
// If the last part of current target path is a folder,
// set target path to empty
let targetPathToUpdate = getTargetPath(commandTargets[0]);
if (commandTargets[0].endsWith('/')) {
targetPathToUpdate = '';
}
const updatedInputValue = getUpdatedInputValueFromTarget(
inputValue,
commandTargets[0],
formatItem(commandResult, 0),
getTargetPath(commandTargets[0]),
targetPathToUpdate,
);

this.setState(
Expand Down

0 comments on commit e66a821

Please sign in to comment.