Skip to content

Commit f13c2f6

Browse files
authored
Merge pull request #142312 from ShafinKhadem/multicursor-searchscope
Respect searchScope column in multicursor selectAll
2 parents 4380f8e + e59dd9c commit f13c2f6

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

src/vs/editor/contrib/multicursor/browser/multicursor.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,18 @@ export class MultiCursorSession {
438438
return new Selection(previousMatch.range.startLineNumber, previousMatch.range.startColumn, previousMatch.range.endLineNumber, previousMatch.range.endColumn);
439439
}
440440

441-
public selectAll(): FindMatch[] {
441+
public selectAll(searchScope: Range[] | null): FindMatch[] {
442442
if (!this._editor.hasModel()) {
443443
return [];
444444
}
445445

446446
this.findController.highlightFindOptions();
447447

448-
return this._editor.getModel().findMatches(this.searchText, true, false, this.matchCase, this.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, false, Constants.MAX_SAFE_SMALL_INTEGER);
448+
const editorModel = this._editor.getModel();
449+
if (searchScope) {
450+
return editorModel.findMatches(this.searchText, searchScope, false, this.matchCase, this.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, false, Constants.MAX_SAFE_SMALL_INTEGER);
451+
}
452+
return editorModel.findMatches(this.searchText, true, false, this.matchCase, this.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, false, Constants.MAX_SAFE_SMALL_INTEGER);
449453
}
450454
}
451455

@@ -617,30 +621,20 @@ export class MultiCursorSelectionController extends Disposable implements IEdito
617621
// - and the search string is non-empty
618622
// - and we're searching for a regex
619623
if (findState.isRevealed && findState.searchString.length > 0 && findState.isRegex) {
620-
621-
matches = this._editor.getModel().findMatches(findState.searchString, true, findState.isRegex, findState.matchCase, findState.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, false, Constants.MAX_SAFE_SMALL_INTEGER);
622-
624+
const editorModel = this._editor.getModel();
625+
if (findState.searchScope) {
626+
matches = editorModel.findMatches(findState.searchString, findState.searchScope, findState.isRegex, findState.matchCase, findState.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, false, Constants.MAX_SAFE_SMALL_INTEGER);
627+
} else {
628+
matches = editorModel.findMatches(findState.searchString, true, findState.isRegex, findState.matchCase, findState.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, false, Constants.MAX_SAFE_SMALL_INTEGER);
629+
}
623630
} else {
624631

625632
this._beginSessionIfNeeded(findController);
626633
if (!this._session) {
627634
return;
628635
}
629636

630-
matches = this._session.selectAll();
631-
}
632-
633-
if (findState.searchScope) {
634-
const states = findState.searchScope;
635-
let inSelection: FindMatch[] | null = [];
636-
matches.forEach((match) => {
637-
states.forEach((state) => {
638-
if (match.range.endLineNumber <= state.endLineNumber && match.range.startLineNumber >= state.startLineNumber) {
639-
inSelection!.push(match);
640-
}
641-
});
642-
});
643-
matches = inSelection;
637+
matches = this._session.selectAll(findState.searchScope);
644638
}
645639

646640
if (matches.length > 0) {

0 commit comments

Comments
 (0)