Used FileMathOrMatch for putting multicursor for search result

This commit is contained in:
Nilesh
2019-11-24 17:07:31 +05:30
parent a0ebd6b08c
commit ce1173d41e
2 changed files with 18 additions and 19 deletions
@@ -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);
}
}
}
@@ -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();