From ce1173d41e7145aa66fd2197fe93757b4e2b75f0 Mon Sep 17 00:00:00 2001 From: Nilesh Date: Sun, 24 Nov 2019 17:03:29 +0530 Subject: [PATCH] Used FileMathOrMatch for putting multicursor for search result --- .../editor/contrib/multicursor/multicursor.ts | 14 +++-------- .../contrib/search/browser/searchView.ts | 23 ++++++++++++------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/vs/editor/contrib/multicursor/multicursor.ts b/src/vs/editor/contrib/multicursor/multicursor.ts index ee80be6a2c2..f2e861e36c8 100644 --- a/src/vs/editor/contrib/multicursor/multicursor.ts +++ b/src/vs/editor/contrib/multicursor/multicursor.ts @@ -632,17 +632,9 @@ export class MultiCursorSelectionController extends Disposable implements IEdito } } - public selectAllUsingString(searchString: string, isRegex: boolean, matchCase: boolean, wholeWord: boolean, limitResultCount?: number): void { - if (!this._editor.hasModel()) { - return; - } - - let matches: FindMatch[] | null = null; - - matches = this._editor.getModel().findMatches(searchString, true, isRegex, matchCase, wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, false, Constants.MAX_SAFE_SMALL_INTEGER); - - if (matches.length > 0) { - this._setSelections(matches.map(m => new Selection(m.range.startLineNumber, m.range.startColumn, m.range.endLineNumber, m.range.endColumn))); + public selectAllUsingSelections(selections: Selection[]): void { + if (selections.length > 0) { + this._setSelections(selections); } } } diff --git a/src/vs/workbench/contrib/search/browser/searchView.ts b/src/vs/workbench/contrib/search/browser/searchView.ts index 4df1c50ebef..46292c294f9 100644 --- a/src/vs/workbench/contrib/search/browser/searchView.ts +++ b/src/vs/workbench/contrib/search/browser/searchView.ts @@ -62,6 +62,7 @@ import { Memento, MementoObject } from 'vs/workbench/common/memento'; import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; import { IOpenerService } from 'vs/platform/opener/common/opener'; import { MultiCursorSelectionController } from 'vs/editor/contrib/multicursor/multicursor'; +import { Selection } from 'vs/editor/common/core/selection'; const $ = dom.$; @@ -1561,15 +1562,21 @@ export class SearchView extends ViewletPanel { } }).then(editor => { if (editor) { - let codeEditor = getCodeEditor(editor.getControl()); - if (codeEditor) { - let multiCursorController = MultiCursorSelectionController.get(codeEditor); - let isRegex = this.searchWidget.searchInput.getRegex(); - let isWholeWords = this.searchWidget.searchInput.getWholeWords(); - let isCaseSensitive = this.searchWidget.searchInput.getCaseSensitive(); - let contentPattern = this.searchWidget.searchInput.getValue(); + let fileMatch = null; + if (element instanceof FileMatch) { + fileMatch = element; + } + else if (element instanceof Match) { + fileMatch = element.parent(); + } - multiCursorController.selectAllUsingString(contentPattern, isRegex, isCaseSensitive, isWholeWords); + if (fileMatch) { + const selections = fileMatch.matches().map(m => new Selection(m.range().startLineNumber, m.range().startColumn, m.range().endLineNumber, m.range().endColumn)); + const codeEditor = getCodeEditor(editor.getControl()); + if (codeEditor) { + let multiCursorController = MultiCursorSelectionController.get(codeEditor); + multiCursorController.selectAllUsingSelections(selections); + } } } this.viewModel.searchResult.rangeHighlightDecorations.removeHighlightRange();