Skip to content

Commit

Permalink
Tab completion of file names is case insensitive on Windows (#7471)
Browse files Browse the repository at this point in the history
Fixes #7160
  • Loading branch information
elazarcoh committed Feb 10, 2022
1 parent 81b21fc commit 84aa6f6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
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);
}
});
});

0 comments on commit 84aa6f6

Please sign in to comment.