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

Replace indexOf with includes in terminal #170235

Merged
merged 2 commits into from
Dec 29, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vs/platform/terminal/common/terminalEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { OperatingSystem, OS } from 'vs/base/common/platform';

export function escapeNonWindowsPath(path: string): string {
let newPath = path;
if (newPath.indexOf('\\') !== 0) {
if (newPath.includes('\\')) {
newPath = newPath.replace(/\\/g, '\\\\');
}
const bannedChars = /[\`\$\|\&\>\~\#\!\^\*\;\<\"\']/g;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/terminal/node/terminalProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ async function detectAvailableUnixProfiles(
// Add non-quick launch profiles
if (includeDetectedProfiles) {
const contents = (await fsProvider.readFile('/etc/shells')).toString();
const profiles = testPaths || contents.split('\n').filter(e => e.trim().indexOf('#') !== 0 && e.trim().length > 0);
const profiles = testPaths || contents.split('\n').filter(e => e.trim().includes('#') && e.trim().length > 0);
const counts: Map<string, number> = new Map();
for (const profile of profiles) {
let profileName = basename(profile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class TerminalFindWidget extends SimpleFindWidget {
}

override reveal(): void {
const initialInput = this._instance.hasSelection() && this._instance.selection!.indexOf('\n') === -1 ? this._instance.selection : undefined;
const initialInput = this._instance.hasSelection() && !this._instance.selection!.includes('\n') ? this._instance.selection : undefined;
const xterm = this._instance.xterm;
if (xterm && this.inputValue && this.inputValue !== '') {
// trigger highlight all matches
Expand All @@ -78,7 +78,7 @@ export class TerminalFindWidget extends SimpleFindWidget {
}

override show() {
const initialInput = this._instance.hasSelection() && this._instance.selection!.indexOf('\n') === -1 ? this._instance.selection : undefined;
const initialInput = this._instance.hasSelection() && !this._instance.selection!.includes('\n') ? this._instance.selection : undefined;
super.show(initialInput);
this._findWidgetVisible.set(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ export class TerminalGroupService extends Disposable implements ITerminalGroupSe
}

getGroupForInstance(instance: ITerminalInstance): ITerminalGroup | undefined {
return this.groups.find(group => group.terminalInstances.indexOf(instance) !== -1);
return this.groups.find(group => group.terminalInstances.includes(instance));
}

getGroupLabels(): string[] {
Expand Down
10 changes: 5 additions & 5 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
private _setCommandsToSkipShell(commands: string[]): void {
const excludeCommands = commands.filter(command => command[0] === '-').map(command => command.slice(1));
this._skipTerminalCommands = DEFAULT_COMMANDS_TO_SKIP_SHELL.filter(defaultCommand => {
return excludeCommands.indexOf(defaultCommand) === -1;
return !excludeCommands.includes(defaultCommand);
}).concat(commands);
}

Expand Down Expand Up @@ -2640,16 +2640,16 @@ async function preparePathForShell(originalPath: string, executable: string | un
return;
}

const hasSpace = originalPath.indexOf(' ') !== -1;
const hasParens = originalPath.indexOf('(') !== -1 || originalPath.indexOf(')') !== -1;
const hasSpace = originalPath.includes(' ');
const hasParens = originalPath.includes('(') || originalPath.includes(')');

const pathBasename = path.basename(executable, '.exe');
const isPowerShell = pathBasename === 'pwsh' ||
title === 'pwsh' ||
pathBasename === 'powershell' ||
title === 'powershell';

if (isPowerShell && (hasSpace || originalPath.indexOf('\'') !== -1)) {
if (isPowerShell && (hasSpace || originalPath.includes('\''))) {
c(`& '${originalPath.replace(/'/g, '\'\'')}'`);
return;
}
Expand Down Expand Up @@ -2677,7 +2677,7 @@ async function preparePathForShell(originalPath: string, executable: string | un
}
} else {
const lowerExecutable = executable.toLowerCase();
if (lowerExecutable.indexOf('wsl') !== -1 || (lowerExecutable.indexOf('bash.exe') !== -1 && lowerExecutable.toLowerCase().indexOf('git') === -1)) {
if (lowerExecutable.includes('wsl') || (lowerExecutable.includes('bash.exe') && !lowerExecutable.toLowerCase().includes('git'))) {
c(backend?.getWslPath(originalPath, 'win-to-unix') || originalPath);
} else if (hasSpace) {
c('"' + originalPath + '"');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ export class MarkNavigationAddon extends Disposable implements IMarkTracker, ITe
}

if (marker === Boundary.Top) {
return this._getMarkers(true).map(e => e.line).indexOf(0) === -1;
return !this._getMarkers(true).map(e => e.line).includes(0);
}

return this._getMarkers(true).indexOf(marker) === -1;
return !this._getMarkers(true).includes(marker);
}

scrollToPreviousMark(scrollPosition: ScrollPosition = ScrollPosition.Middle, retainSelection: boolean = false, skipEmptyCommands: boolean = false): void {
Expand Down