diff --git a/src/actions/commands/commandLine.ts b/src/actions/commands/commandLine.ts index 6b455fc6383..d922e2d6702 100644 --- a/src/actions/commands/commandLine.ts +++ b/src/actions/commands/commandLine.ts @@ -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(); } diff --git a/test/cmd_line/tabCompletion.test.ts b/test/cmd_line/tabCompletion.test.ts index 1d8fa054a82..d594d65f42a 100644 --- a/test/cmd_line/tabCompletion.test.ts +++ b/test/cmd_line/tabCompletion.test.ts @@ -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(''); + const statusBarAfterTab = StatusBar.getText().trim(); + await modeHandler.handleKeyEvent(''); + 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(''); + const statusBarAfterTab = StatusBar.getText().trim(); + await modeHandler.handleKeyEvent(''); + assert.strictEqual(statusBarBeforeTab, statusBarAfterTab, 'Is case-insensitive on non-windows'); + } + + } finally { + await t.removeFile(filePath); + await t.removeDir(dirPath); + } + }); });