Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tab completion of file names is case insensitive on Windows #7471

Merged
merged 5 commits into from
Feb 10, 2022
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
9 changes: 7 additions & 2 deletions src/actions/commands/commandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,14 @@ class CommandLineTab extends CommandLineAction {
isRemote,
shouldAddDotItems
);
const startWithBaseNameRegex = new RegExp(
`^${baseName}`,
process.platform === 'win32' ? 'i' : ''
);
newCompletionItems = dirItems
.filter((name) => name.startsWith(baseName))
.map((name) => name.slice(name.search(baseName) + baseName.length))
.map((name): [RegExpExecArray | null, string] => [startWithBaseNameRegex.exec(name), name])
.filter(([isMatch]) => isMatch !== null)
.map(([match, name]) => name.slice(match![0].length))
.sort();
}

Expand Down
33 changes: 33 additions & 0 deletions test/cmd_line/tabCompletion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,37 @@ suite('cmd_line tabComplete', () => {
await t.removeFile(spacedFilePath);
}
});

test('command line file tab completion case-sensitivity platform dependent', async () => {
const dirPath = await t.createRandomDir();
const filePath = await t.createEmptyFile(join(dirPath, 'testfile'));
const fileAsTyped = join(dirPath, 'TESTFIL');
const cmd = `:e ${fileAsTyped}`.split('');

try {
if (process.platform === 'win32') {
await modeHandler.handleMultipleKeyEvents(cmd);
await modeHandler.handleKeyEvent('<tab>');
const statusBarAfterTab = StatusBar.getText().trim();
await modeHandler.handleKeyEvent('<Esc>');
assert.strictEqual(
statusBarAfterTab.toLowerCase(),
`:e ${filePath}|`.toLowerCase(),
'Cannot complete path case-insensitive on windows'
);
}
else {
await modeHandler.handleMultipleKeyEvents(cmd);
const statusBarBeforeTab = StatusBar.getText();
await modeHandler.handleKeyEvent('<tab>');
const statusBarAfterTab = StatusBar.getText().trim();
await modeHandler.handleKeyEvent('<Esc>');
assert.strictEqual(statusBarBeforeTab, statusBarAfterTab, 'Is case-insensitive on non-windows');
}

} finally {
await t.removeFile(filePath);
await t.removeDir(dirPath);
}
});
});