Skip to content

Commit 846dde8

Browse files
committed
add more tests.
1 parent 1bea038 commit 846dde8

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

src/vs/editor/common/model/textModel.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,18 @@ export class TextModel extends Disposable implements model.ITextModel {
11371137
searchRanges = [this.getFullModelRange()];
11381138
}
11391139

1140+
searchRanges = searchRanges.sort((d1, d2) => d1.startLineNumber - d2.startLineNumber || d1.startColumn - d2.startColumn);
1141+
1142+
const uniqueSearchRanges: Range[] = [];
1143+
uniqueSearchRanges.push(searchRanges.reduce((prev, curr) => {
1144+
if (Range.areIntersecting(prev, curr)) {
1145+
return prev.plusRange(curr);
1146+
}
1147+
1148+
uniqueSearchRanges.push(prev);
1149+
return curr;
1150+
}));
1151+
11401152
let matchMapper: (value: Range, index: number, array: Range[]) => model.FindMatch[];
11411153
if (!isRegex && searchString.indexOf('\n') < 0) {
11421154
// not regex, not multi line
@@ -1152,7 +1164,7 @@ export class TextModel extends Disposable implements model.ITextModel {
11521164
matchMapper = (searchRange: Range) => TextModelSearch.findMatches(this, new SearchParams(searchString, isRegex, matchCase, wordSeparators), searchRange, captureMatches, limitResultCount);
11531165
}
11541166

1155-
return searchRanges.map(matchMapper).reduce((arr, matches: model.FindMatch[]) => arr.concat(matches), []);
1167+
return uniqueSearchRanges.map(matchMapper).reduce((arr, matches: model.FindMatch[]) => arr.concat(matches), []);
11561168
}
11571169

11581170
public findNextMatch(searchString: string, rawSearchStart: IPosition, isRegex: boolean, matchCase: boolean, wordSeparators: string, captureMatches: boolean): model.FindMatch | null {

src/vs/editor/contrib/find/test/findModel.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,58 @@ suite('FindModel', () => {
493493
findState.dispose();
494494
});
495495

496+
findTest('multi-selection find model next stays in scope (overlap)', (editor) => {
497+
let findState = new FindReplaceState();
498+
findState.change({ searchString: 'hello', wholeWord: true, searchScope: [new Range(7, 1, 8, 2), new Range(8, 1, 9, 1)] }, false);
499+
let findModel = new FindModelBoundToEditorModel(editor, findState);
500+
501+
assertFindState(
502+
editor,
503+
[1, 1, 1, 1],
504+
null,
505+
[
506+
[7, 14, 7, 19],
507+
[8, 14, 8, 19]
508+
]
509+
);
510+
511+
findModel.moveToNextMatch();
512+
assertFindState(
513+
editor,
514+
[7, 14, 7, 19],
515+
[7, 14, 7, 19],
516+
[
517+
[7, 14, 7, 19],
518+
[8, 14, 8, 19]
519+
]
520+
);
521+
522+
findModel.moveToNextMatch();
523+
assertFindState(
524+
editor,
525+
[8, 14, 8, 19],
526+
[8, 14, 8, 19],
527+
[
528+
[7, 14, 7, 19],
529+
[8, 14, 8, 19]
530+
]
531+
);
532+
533+
findModel.moveToNextMatch();
534+
assertFindState(
535+
editor,
536+
[7, 14, 7, 19],
537+
[7, 14, 7, 19],
538+
[
539+
[7, 14, 7, 19],
540+
[8, 14, 8, 19]
541+
]
542+
);
543+
544+
findModel.dispose();
545+
findState.dispose();
546+
});
547+
496548
findTest('multi-selection find model next stays in scope', (editor) => {
497549
let findState = new FindReplaceState();
498550
findState.change({ searchString: 'hello', matchCase: true, wholeWord: false, searchScope: [new Range(6, 1, 7, 38), new Range(9, 3, 9, 38)] }, false);

0 commit comments

Comments
 (0)