Skip to content

Commit a6470cb

Browse files
CGNonofrLoïc Mangeonjean
andauthored
Replace map by foreach (microsoft#199194)
* refactor: replace map by forEach * fix: fix suspicious code --------- Co-authored-by: Loïc Mangeonjean <[email protected]>
1 parent bc00185 commit a6470cb

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

src/vs/editor/contrib/find/browser/findController.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { INotificationService, Severity } from 'vs/platform/notification/common/
3030
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
3131
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
3232
import { IThemeService, themeColorFromId } from 'vs/platform/theme/common/themeService';
33+
import { Selection } from 'vs/editor/common/core/selection';
3334

3435
const SEARCH_STRING_MAX_LENGTH = 524288;
3536

@@ -258,8 +259,8 @@ export class CommonFindController extends Disposable implements IEditorContribut
258259
this._state.change({ searchScope: null }, true);
259260
} else {
260261
if (this._editor.hasModel()) {
261-
const selections = this._editor.getSelections();
262-
selections.map(selection => {
262+
let selections = this._editor.getSelections();
263+
selections = selections.map(selection => {
263264
if (selection.endColumn === 1 && selection.endLineNumber > selection.startLineNumber) {
264265
selection = selection.setEndPosition(
265266
selection.endLineNumber - 1,
@@ -270,7 +271,7 @@ export class CommonFindController extends Disposable implements IEditorContribut
270271
return selection;
271272
}
272273
return null;
273-
}).filter(element => !!element);
274+
}).filter((element): element is Selection => !!element);
274275

275276
if (selections.length) {
276277
this._state.change({ searchScope: selections }, true);

src/vs/editor/contrib/find/browser/findWidget.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { ThemeIcon } from 'vs/base/common/themables';
4343
import { isHighContrast } from 'vs/platform/theme/common/theme';
4444
import { assertIsDefined } from 'vs/base/common/types';
4545
import { defaultInputBoxStyles, defaultToggleStyles } from 'vs/platform/theme/browser/defaultStyles';
46+
import { Selection } from 'vs/editor/common/core/selection';
4647

4748
const findSelectionIcon = registerIcon('find-selection', Codicon.selection, nls.localize('findSelectionIcon', 'Icon for \'Find in Selection\' in the editor find widget.'));
4849
const findCollapsedIcon = registerIcon('find-collapsed', Codicon.chevronRight, nls.localize('findCollapsedIcon', 'Icon to indicate that the editor find widget is collapsed.'));
@@ -1051,16 +1052,16 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL
10511052
this._register(this._toggleSelectionFind.onChange(() => {
10521053
if (this._toggleSelectionFind.checked) {
10531054
if (this._codeEditor.hasModel()) {
1054-
const selections = this._codeEditor.getSelections();
1055-
selections.map(selection => {
1055+
let selections = this._codeEditor.getSelections();
1056+
selections = selections.map(selection => {
10561057
if (selection.endColumn === 1 && selection.endLineNumber > selection.startLineNumber) {
10571058
selection = selection.setEndPosition(selection.endLineNumber - 1, this._codeEditor.getModel()!.getLineMaxColumn(selection.endLineNumber - 1));
10581059
}
10591060
if (!selection.isEmpty()) {
10601061
return selection;
10611062
}
10621063
return null;
1063-
}).filter(element => !!element);
1064+
}).filter((element): element is Selection => !!element);
10641065

10651066
if (selections.length) {
10661067
this._state.change({ searchScope: selections as Range[] }, true);

src/vs/workbench/browser/parts/editor/editorGroupWatermark.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class EditorGroupWatermark extends Disposable {
135135

136136
const update = () => {
137137
clearNode(box);
138-
selected.map(entry => {
138+
selected.forEach(entry => {
139139
const keys = this.keybindingService.lookupKeybinding(entry.id);
140140
if (!keys) {
141141
return;

src/vs/workbench/contrib/extensions/browser/extensions.contribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ class ExtensionsContributions extends Disposable implements IWorkbenchContributi
992992
order: 1,
993993
});
994994

995-
EXTENSION_CATEGORIES.map((category, index) => {
995+
EXTENSION_CATEGORIES.forEach((category, index) => {
996996
this.registerExtensionAction({
997997
id: `extensions.actions.searchByCategory.${category}`,
998998
title: category,

src/vs/workbench/contrib/search/browser/searchModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2372,7 +2372,7 @@ function textSearchResultToMatches(rawMatch: ITextSearchMatch, fileMatch: FileMa
23722372

23732373
export function textSearchMatchesToNotebookMatches(textSearchMatches: ITextSearchMatch[], cell: CellMatch): MatchInNotebook[] {
23742374
const notebookMatches: MatchInNotebook[] = [];
2375-
textSearchMatches.map((textSearchMatch) => {
2375+
textSearchMatches.forEach((textSearchMatch) => {
23762376
const previewLines = textSearchMatch.preview.text.split('\n');
23772377
if (Array.isArray(textSearchMatch.ranges)) {
23782378
textSearchMatch.ranges.forEach((r, i) => {

0 commit comments

Comments
 (0)