Skip to content

Commit 2ef1c75

Browse files
committed
💄 from microsoft#48999
1 parent f427a41 commit 2ef1c75

4 files changed

Lines changed: 35 additions & 30 deletions

File tree

src/vs/workbench/parts/search/browser/searchActions.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import * as DOM from 'vs/base/browser/dom';
88
import { TPromise } from 'vs/base/common/winjs.base';
99
import { Action } from 'vs/base/common/actions';
1010
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
11-
import { ITree, ISorter } from 'vs/base/parts/tree/browser/tree';
11+
import { ITree } from 'vs/base/parts/tree/browser/tree';
1212
import { INavigator } from 'vs/base/common/iterator';
1313
import { SearchView } from 'vs/workbench/parts/search/browser/searchView';
14-
import { Match, FileMatch, FileMatchOrMatch, FolderMatch, RenderableMatch, SearchResult } from 'vs/workbench/parts/search/common/searchModel';
15-
import { Range } from 'vs/editor/common/core/range';
14+
import { Match, FileMatch, FileMatchOrMatch, FolderMatch, RenderableMatch, SearchResult, searchMatchComparer } from 'vs/workbench/parts/search/common/searchModel';
1615
import { IReplaceService } from 'vs/workbench/parts/search/common/replace';
1716
import * as Constants from 'vs/workbench/parts/search/common/constants';
1817
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
@@ -714,8 +713,8 @@ function matchToString(match: Match): string {
714713

715714
const lineDelimiter = isWindows ? '\r\n' : '\n';
716715
function fileMatchToString(fileMatch: FileMatch, maxMatches: number): { text: string, count: number } {
717-
let matches = fileMatch.matches().sort(matchComparer);
718-
const matchTextRows = matches
716+
const matchTextRows = fileMatch.matches()
717+
.sort(searchMatchComparer)
719718
.slice(0, maxMatches)
720719
.map(matchToString)
721720
.map(matchText => ' ' + matchText);
@@ -729,7 +728,7 @@ function folderMatchToString(folderMatch: FolderMatch, maxMatches: number): { te
729728
const fileResults: string[] = [];
730729
let numMatches = 0;
731730

732-
let matches = folderMatch.matches().sort(matchComparer);
731+
let matches = folderMatch.matches().sort(searchMatchComparer);
733732

734733
for (let i = 0; i < folderMatch.fileCount() && numMatches < maxMatches; i++) {
735734
const fileResult = fileMatchToString(matches[i], maxMatches - numMatches);
@@ -760,30 +759,11 @@ export const copyMatchCommand: ICommandHandler = (accessor, match: RenderableMat
760759
clipboardService.writeText(text);
761760
}
762761
};
763-
function matchComparer(elementA: RenderableMatch, elementB: RenderableMatch): number {
764-
if (elementA instanceof FolderMatch && elementB instanceof FolderMatch) {
765-
return elementA.index() - elementB.index();
766-
}
767-
768-
if (elementA instanceof FileMatch && elementB instanceof FileMatch) {
769-
return elementA.resource().fsPath.localeCompare(elementB.resource().fsPath) || elementA.name().localeCompare(elementB.name());
770-
}
771-
772-
if (elementA instanceof Match && elementB instanceof Match) {
773-
return Range.compareRangesUsingStarts(elementA.range(), elementB.range());
774-
}
775-
return undefined;
776-
}
777-
export class SearchSorter implements ISorter {
778-
public compare(tree: ITree, elementA: RenderableMatch, elementB: RenderableMatch): number {
779-
return matchComparer(elementA, elementB);
780-
}
781-
}
782762

783763
function allFolderMatchesToString(folderMatches: FolderMatch[], maxMatches: number): string {
784764
const folderResults: string[] = [];
785765
let numMatches = 0;
786-
folderMatches.sort(matchComparer);
766+
folderMatches = folderMatches.sort(searchMatchComparer);
787767
for (let i = 0; i < folderMatches.length && numMatches < maxMatches; i++) {
788768
const folderResult = folderMatchToString(folderMatches[i], maxMatches - numMatches);
789769
if (folderResult.count) {

src/vs/workbench/parts/search/browser/searchResultsView.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { IAction, IActionRunner } from 'vs/base/common/actions';
1212
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
1313
import { CountBadge } from 'vs/base/browser/ui/countBadge/countBadge';
1414
import { FileLabel } from 'vs/workbench/browser/labels';
15-
import { ITree, IDataSource, IAccessibilityProvider, IFilter, IRenderer, ContextMenuEvent } from 'vs/base/parts/tree/browser/tree';
16-
import { Match, SearchResult, FileMatch, FileMatchOrMatch, SearchModel, FolderMatch } from 'vs/workbench/parts/search/common/searchModel';
15+
import { ITree, IDataSource, IAccessibilityProvider, IFilter, IRenderer, ContextMenuEvent, ISorter } from 'vs/base/parts/tree/browser/tree';
16+
import { Match, SearchResult, FileMatch, FileMatchOrMatch, SearchModel, FolderMatch, searchMatchComparer, RenderableMatch } from 'vs/workbench/parts/search/common/searchModel';
1717
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
1818
import { SearchView } from 'vs/workbench/parts/search/browser/searchView';
1919
import { RemoveAction, ReplaceAllAction, ReplaceAction, ReplaceAllInFolderAction } from 'vs/workbench/parts/search/browser/searchActions';
@@ -110,6 +110,11 @@ export class SearchDataSource implements IDataSource {
110110
}
111111
}
112112

113+
export class SearchSorter implements ISorter {
114+
public compare(tree: ITree, elementA: RenderableMatch, elementB: RenderableMatch): number {
115+
return searchMatchComparer(elementA, elementB);
116+
}
117+
}
113118

114119
interface IFolderMatchTemplate {
115120
label: FileLabel;

src/vs/workbench/parts/search/browser/searchView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/c
4141
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
4242
import { KeyCode } from 'vs/base/common/keyCodes';
4343
import { PatternInputWidget, ExcludePatternInputWidget } from 'vs/workbench/parts/search/browser/patternInputWidget';
44-
import { SearchRenderer, SearchDataSource, SearchAccessibilityProvider, SearchFilter, SearchTreeController } from 'vs/workbench/parts/search/browser/searchResultsView';
44+
import { SearchRenderer, SearchDataSource, SearchAccessibilityProvider, SearchFilter, SearchTreeController, SearchSorter } from 'vs/workbench/parts/search/browser/searchResultsView';
4545
import { SearchWidget, ISearchWidgetOptions } from 'vs/workbench/parts/search/browser/searchWidget';
46-
import { SearchSorter, RefreshAction, CollapseDeepestExpandedLevelAction, ClearSearchResultsAction, CancelSearchAction } from 'vs/workbench/parts/search/browser/searchActions';
46+
import { RefreshAction, CollapseDeepestExpandedLevelAction, ClearSearchResultsAction, CancelSearchAction } from 'vs/workbench/parts/search/browser/searchActions';
4747
import { IReplaceService } from 'vs/workbench/parts/search/common/replace';
4848
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
4949
import { OpenFolderAction, OpenFileFolderAction } from 'vs/workbench/browser/actions/workspaceActions';

src/vs/workbench/parts/search/common/searchModel.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,26 @@ export class FolderMatch extends Disposable {
497497
}
498498
}
499499

500+
/**
501+
* Compares instances of the same match type. Different match types should not be siblings
502+
* and their sort order is undefined.
503+
*/
504+
export function searchMatchComparer(elementA: RenderableMatch, elementB: RenderableMatch): number {
505+
if (elementA instanceof FolderMatch && elementB instanceof FolderMatch) {
506+
return elementA.index() - elementB.index();
507+
}
508+
509+
if (elementA instanceof FileMatch && elementB instanceof FileMatch) {
510+
return elementA.resource().fsPath.localeCompare(elementB.resource().fsPath) || elementA.name().localeCompare(elementB.name());
511+
}
512+
513+
if (elementA instanceof Match && elementB instanceof Match) {
514+
return Range.compareRangesUsingStarts(elementA.range(), elementB.range());
515+
}
516+
517+
return undefined;
518+
}
519+
500520
export class SearchResult extends Disposable {
501521

502522
private _onChange = this._register(new Emitter<IChangeEvent>());

0 commit comments

Comments
 (0)