@@ -8,11 +8,10 @@ import * as DOM from 'vs/base/browser/dom';
88import { TPromise } from 'vs/base/common/winjs.base' ;
99import { Action } from 'vs/base/common/actions' ;
1010import { 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' ;
1212import { INavigator } from 'vs/base/common/iterator' ;
1313import { 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' ;
1615import { IReplaceService } from 'vs/workbench/parts/search/common/replace' ;
1716import * as Constants from 'vs/workbench/parts/search/common/constants' ;
1817import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService' ;
@@ -714,8 +713,8 @@ function matchToString(match: Match): string {
714713
715714const lineDelimiter = isWindows ? '\r\n' : '\n' ;
716715function 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
783763function 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 ) {
0 commit comments