提交 3e7c371e 编写于 作者: S Shiva Prasanth

search results copy All with sort like tree

上级 55a10f77
......@@ -8,10 +8,11 @@ import * as DOM from 'vs/base/browser/dom';
import { TPromise } from 'vs/base/common/winjs.base';
import { Action } from 'vs/base/common/actions';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { ITree } from 'vs/base/parts/tree/browser/tree';
import { ITree, ISorter } from 'vs/base/parts/tree/browser/tree';
import { INavigator } from 'vs/base/common/iterator';
import { SearchView } from 'vs/workbench/parts/search/browser/searchView';
import { Match, FileMatch, FileMatchOrMatch, FolderMatch, RenderableMatch, SearchResult } from 'vs/workbench/parts/search/common/searchModel';
import { Range } from 'vs/editor/common/core/range';
import { IReplaceService } from 'vs/workbench/parts/search/common/replace';
import * as Constants from 'vs/workbench/parts/search/common/constants';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
......@@ -717,7 +718,6 @@ function fileMatchToString(fileMatch: FileMatch, maxMatches: number): { text: st
.slice(0, maxMatches)
.map(matchToString)
.map(matchText => ' ' + matchText);
return {
text: `${uriToClipboardString(fileMatch.resource())}${lineDelimiter}${matchTextRows.join(lineDelimiter)}`,
count: matchTextRows.length
......@@ -728,8 +728,11 @@ function folderMatchToString(folderMatch: FolderMatch, maxMatches: number): { te
const fileResults: string[] = [];
let numMatches = 0;
let sorter = new SearchSorter();
let matches = folderMatch.matches().sort((matchA, matchB) => sorter.compare(null, matchA, matchB));
for (let i = 0; i < folderMatch.fileCount() && numMatches < maxMatches; i++) {
const fileResult = fileMatchToString(folderMatch.matches()[i], maxMatches - numMatches);
const fileResult = fileMatchToString(matches[i], maxMatches - numMatches);
numMatches += fileResult.count;
fileResults.push(fileResult.text);
}
......@@ -758,10 +761,26 @@ export const copyMatchCommand: ICommandHandler = (accessor, match: RenderableMat
}
};
export class SearchSorter implements ISorter {
public compare(tree: ITree, elementA: FileMatchOrMatch, elementB: FileMatchOrMatch): number {
if (elementA instanceof FolderMatch && elementB instanceof FolderMatch) {
return elementA.index() - elementB.index();
}
if (elementA instanceof FileMatch && elementB instanceof FileMatch) {
return elementA.resource().fsPath.localeCompare(elementB.resource().fsPath) || elementA.name().localeCompare(elementB.name());
}
if (elementA instanceof Match && elementB instanceof Match) {
return Range.compareRangesUsingStarts(elementA.range(), elementB.range());
}
return undefined;
}
}
function allFolderMatchesToString(folderMatches: FolderMatch[], maxMatches: number): string {
const folderResults: string[] = [];
let numMatches = 0;
for (let i = 0; i < folderMatches.length && numMatches < maxMatches; i++) {
const folderResult = folderMatchToString(folderMatches[i], maxMatches - numMatches);
if (folderResult.count) {
......@@ -791,4 +810,4 @@ export const clearHistoryCommand: ICommandHandler = accessor => {
const searchView = getSearchView(viewletService, panelService);
searchView.clearHistory();
};
};
\ No newline at end of file
......@@ -12,10 +12,9 @@ import { IAction, IActionRunner } from 'vs/base/common/actions';
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import { CountBadge } from 'vs/base/browser/ui/countBadge/countBadge';
import { FileLabel } from 'vs/workbench/browser/labels';
import { ITree, IDataSource, ISorter, IAccessibilityProvider, IFilter, IRenderer, ContextMenuEvent } from 'vs/base/parts/tree/browser/tree';
import { ITree, IDataSource, IAccessibilityProvider, IFilter, IRenderer, ContextMenuEvent } from 'vs/base/parts/tree/browser/tree';
import { Match, SearchResult, FileMatch, FileMatchOrMatch, SearchModel, FolderMatch } from 'vs/workbench/parts/search/common/searchModel';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { Range } from 'vs/editor/common/core/range';
import { SearchView } from 'vs/workbench/parts/search/browser/searchView';
import { RemoveAction, ReplaceAllAction, ReplaceAction, ReplaceAllInFolderAction } from 'vs/workbench/parts/search/browser/searchActions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
......@@ -111,24 +110,6 @@ export class SearchDataSource implements IDataSource {
}
}
export class SearchSorter implements ISorter {
public compare(tree: ITree, elementA: FileMatchOrMatch, elementB: FileMatchOrMatch): number {
if (elementA instanceof FolderMatch && elementB instanceof FolderMatch) {
return elementA.index() - elementB.index();
}
if (elementA instanceof FileMatch && elementB instanceof FileMatch) {
return elementA.resource().fsPath.localeCompare(elementB.resource().fsPath) || elementA.name().localeCompare(elementB.name());
}
if (elementA instanceof Match && elementB instanceof Match) {
return Range.compareRangesUsingStarts(elementA.range(), elementB.range());
}
return undefined;
}
}
interface IFolderMatchTemplate {
label: FileLabel;
......@@ -395,4 +376,4 @@ export class SearchTreeController extends WorkbenchTreeController {
return true;
}
}
}
\ No newline at end of file
......@@ -41,9 +41,9 @@ import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/c
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { KeyCode } from 'vs/base/common/keyCodes';
import { PatternInputWidget, ExcludePatternInputWidget } from 'vs/workbench/parts/search/browser/patternInputWidget';
import { SearchRenderer, SearchDataSource, SearchSorter, SearchAccessibilityProvider, SearchFilter, SearchTreeController } from 'vs/workbench/parts/search/browser/searchResultsView';
import { SearchRenderer, SearchDataSource, SearchAccessibilityProvider, SearchFilter, SearchTreeController } from 'vs/workbench/parts/search/browser/searchResultsView';
import { SearchWidget, ISearchWidgetOptions } from 'vs/workbench/parts/search/browser/searchWidget';
import { RefreshAction, CollapseDeepestExpandedLevelAction, ClearSearchResultsAction, CancelSearchAction } from 'vs/workbench/parts/search/browser/searchActions';
import { SearchSorter, RefreshAction, CollapseDeepestExpandedLevelAction, ClearSearchResultsAction, CancelSearchAction } from 'vs/workbench/parts/search/browser/searchActions';
import { IReplaceService } from 'vs/workbench/parts/search/common/replace';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { OpenFolderAction, OpenFileFolderAction } from 'vs/workbench/browser/actions/workspaceActions';
......@@ -1585,4 +1585,4 @@ registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => {
if (findMatchHighlightBorder) {
collector.addRule(`.monaco-workbench .search-view .findInFileMatch { border: 1px ${theme.type === 'hc' ? 'dashed' : 'solid'} ${findMatchHighlightBorder}; }`);
}
});
});
\ No newline at end of file
......@@ -8,7 +8,8 @@ import * as assert from 'assert';
import uri from 'vs/base/common/uri';
import { Match, FileMatch, SearchResult } from 'vs/workbench/parts/search/common/searchModel';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { SearchSorter, SearchDataSource } from 'vs/workbench/parts/search/browser/searchResultsView';
import { SearchSorter } from 'vs/workbench/parts/search/browser/searchActions';
import { SearchDataSource } from 'vs/workbench/parts/search/browser/searchResultsView';
import { IFileMatch, ILineMatch } from 'vs/platform/search/common/search';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册