提交 4d4f9638 编写于 作者: R Rob Lourens

Fix #68399 - fix tree errors when removing items from the search results tree

上级 df619d25
......@@ -122,7 +122,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
handler: (accessor, args: any) => {
const searchView = getSearchView(accessor.get(IViewletService), accessor.get(IPanelService));
const tree: WorkbenchObjectTree<RenderableMatch> = searchView.getControl();
accessor.get(IInstantiationService).createInstance(RemoveAction, searchView, tree, tree.getFocus()[0]).run();
accessor.get(IInstantiationService).createInstance(RemoveAction, tree, tree.getFocus()[0]).run();
}
});
......
......@@ -25,7 +25,7 @@ import { ISearchConfiguration, ISearchHistoryService, VIEW_ID } from 'vs/workben
import { SearchView } from 'vs/workbench/contrib/search/browser/searchView';
import * as Constants from 'vs/workbench/contrib/search/common/constants';
import { IReplaceService } from 'vs/workbench/contrib/search/common/replace';
import { FileMatch, FileMatchOrMatch, FolderMatch, Match, RenderableMatch, searchMatchComparer, SearchResult } from 'vs/workbench/contrib/search/common/searchModel';
import { FileMatch, FileMatchOrMatch, FolderMatch, Match, RenderableMatch, searchMatchComparer, SearchResult, BaseFolderMatch } from 'vs/workbench/contrib/search/common/searchModel';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
......@@ -277,7 +277,7 @@ export class CollapseDeepestExpandedLevelAction extends Action {
const navigator = viewer.navigate();
let node = navigator.first();
let collapseFileMatchLevel = false;
if (node instanceof FolderMatch) {
if (node instanceof BaseFolderMatch) {
while (node = navigator.next()) {
if (node instanceof Match) {
collapseFileMatchLevel = true;
......@@ -407,8 +407,8 @@ export abstract class AbstractSearchAndReplaceAction extends Action {
getNextElementAfterRemoved(viewer: WorkbenchObjectTree<RenderableMatch>, element: RenderableMatch): RenderableMatch {
const navigator: INavigator<any> = viewer.navigate(element);
if (element instanceof FolderMatch) {
while (!!navigator.next() && !(navigator.current() instanceof FolderMatch)) { }
if (element instanceof BaseFolderMatch) {
while (!!navigator.next() && !(navigator.current() instanceof BaseFolderMatch)) { }
} else if (element instanceof FileMatch) {
while (!!navigator.next() && !(navigator.current() instanceof FileMatch)) { }
} else {
......@@ -435,7 +435,7 @@ export abstract class AbstractSearchAndReplaceAction extends Action {
// If the previous element is a File or Folder, expand it and go to its last child.
// Spell out the two cases, would be too easy to create an infinite loop, like by adding another level...
if (element instanceof Match && previousElement && previousElement instanceof FolderMatch) {
if (element instanceof Match && previousElement && previousElement instanceof BaseFolderMatch) {
navigator.next();
viewer.expand(previousElement);
previousElement = navigator.previous();
......@@ -456,7 +456,6 @@ export class RemoveAction extends AbstractSearchAndReplaceAction {
static LABEL = nls.localize('RemoveAction.label', "Dismiss");
constructor(
private viewlet: SearchView,
private viewer: WorkbenchObjectTree<RenderableMatch>,
private element: RenderableMatch
) {
......@@ -474,24 +473,9 @@ export class RemoveAction extends AbstractSearchAndReplaceAction {
this.viewer.setFocus([nextFocusElement], getKeyboardEventForEditorOpen());
}
let elementToRefresh: FolderMatch | FileMatch | SearchResult | undefined;
const element = this.element;
if (element instanceof FolderMatch) {
const parent = element.parent();
parent.remove(element);
elementToRefresh = parent;
} else if (element instanceof FileMatch) {
const parent = element.parent();
parent.remove(element);
elementToRefresh = parent;
} else if (element instanceof Match) {
const parent = element.parent();
parent.remove(element);
elementToRefresh = parent.count() === 0 ? parent.parent() : parent;
}
this.element.parent().remove(<any>this.element);
this.viewer.domFocus();
this.viewlet.refreshTree({ elements: [elementToRefresh] });
return Promise.resolve();
}
}
......@@ -716,7 +700,7 @@ export const copyMatchCommand: ICommandHandler = (accessor, match: RenderableMat
text = matchToString(match);
} else if (match instanceof FileMatch) {
text = fileMatchToString(match, maxClipboardMatches).text;
} else if (match instanceof FolderMatch) {
} else if (match instanceof BaseFolderMatch) {
text = folderMatchToString(match, maxClipboardMatches).text;
}
......
......@@ -135,7 +135,7 @@ export class FolderMatchRenderer extends Disposable implements ITreeRenderer<Fol
actions.push(this.instantiationService.createInstance(ReplaceAllInFolderAction, this.searchView.getControl(), folderMatch));
}
actions.push(new RemoveAction(this.searchView, this.searchView.getControl(), folderMatch));
actions.push(new RemoveAction(this.searchView.getControl(), folderMatch));
templateData.actions.push(actions, { icon: true, label: false });
}
......@@ -197,7 +197,7 @@ export class FileMatchRenderer extends Disposable implements ITreeRenderer<FileM
if (this.searchModel.isReplaceActive() && count > 0) {
actions.push(this.instantiationService.createInstance(ReplaceAllAction, this.searchView, fileMatch));
}
actions.push(new RemoveAction(this.searchView, this.searchView.getControl(), fileMatch));
actions.push(new RemoveAction(this.searchView.getControl(), fileMatch));
templateData.actions.push(actions, { icon: true, label: false });
}
......@@ -271,9 +271,9 @@ export class MatchRenderer extends Disposable implements ITreeRenderer<Match, vo
templateData.actions.clear();
if (this.searchModel.isReplaceActive()) {
templateData.actions.push([this.instantiationService.createInstance(ReplaceAction, this.searchView.getControl(), match, this.searchView), new RemoveAction(this.searchView, this.searchView.getControl(), match)], { icon: true, label: false });
templateData.actions.push([this.instantiationService.createInstance(ReplaceAction, this.searchView.getControl(), match, this.searchView), new RemoveAction(this.searchView.getControl(), match)], { icon: true, label: false });
} else {
templateData.actions.push([new RemoveAction(this.searchView, this.searchView.getControl(), match)], { icon: true, label: false });
templateData.actions.push([new RemoveAction(this.searchView.getControl(), match)], { icon: true, label: false });
}
}
......@@ -309,7 +309,7 @@ export class SearchAccessibilityProvider implements IAccessibilityProvider<Rende
}
getAriaLabel(element: RenderableMatch): string {
if (element instanceof FolderMatch) {
if (element instanceof BaseFolderMatch) {
return element.hasResource() ?
nls.localize('folderMatchAriaLabel', "{0} matches in folder root {1}, Search result", element.count(), element.name()) :
nls.localize('otherFilesAriaLabel', "{0} matches outside of the workspace, Search result", element.count());
......
......@@ -55,7 +55,7 @@ import * as Constants from 'vs/workbench/contrib/search/common/constants';
import { ITextQueryBuilderOptions, QueryBuilder } from 'vs/workbench/contrib/search/common/queryBuilder';
import { IReplaceService } from 'vs/workbench/contrib/search/common/replace';
import { getOutOfWorkspaceEditorResources } from 'vs/workbench/contrib/search/common/search';
import { FileMatch, FileMatchOrMatch, FolderMatch, IChangeEvent, ISearchWorkbenchService, Match, RenderableMatch, searchMatchComparer, SearchModel, SearchResult } from 'vs/workbench/contrib/search/common/searchModel';
import { FileMatch, FileMatchOrMatch, FolderMatch, IChangeEvent, ISearchWorkbenchService, Match, RenderableMatch, searchMatchComparer, SearchModel, SearchResult, BaseFolderMatch } from 'vs/workbench/contrib/search/common/searchModel';
import { ACTIVE_GROUP, IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IPartService } from 'vs/workbench/services/part/common/partService';
......@@ -443,7 +443,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
this.tree.setChildren(null, this.createResultIterator(collapseResults));
} else {
event.elements.forEach(element => {
if (element instanceof FolderMatch) {
if (element instanceof BaseFolderMatch) {
// The folder may or may not be in the tree. Refresh the whole thing.
this.tree.setChildren(null, this.createResultIterator(collapseResults));
return;
......@@ -496,9 +496,9 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
return Iterator.map(matchesIt, r => (<ITreeElement<RenderableMatch>>{ element: r }));
}
private createIterator(match: FolderMatch | FileMatch | SearchResult, collapseResults: ISearchConfigurationProperties['collapseResults']): Iterator<ITreeElement<RenderableMatch>> {
private createIterator(match: BaseFolderMatch | FileMatch | SearchResult, collapseResults: ISearchConfigurationProperties['collapseResults']): Iterator<ITreeElement<RenderableMatch>> {
return match instanceof SearchResult ? this.createResultIterator(collapseResults) :
match instanceof FolderMatch ? this.createFolderIterator(match, collapseResults) :
match instanceof BaseFolderMatch ? this.createFolderIterator(match, collapseResults) :
this.createFileIterator(match);
}
......
......@@ -598,7 +598,7 @@ export class FolderMatch extends BaseFolderMatch {
* and their sort order is undefined.
*/
export function searchMatchComparer(elementA: RenderableMatch, elementB: RenderableMatch): number {
if (elementA instanceof FolderMatch && elementB instanceof FolderMatch) {
if (elementA instanceof BaseFolderMatch && elementB instanceof BaseFolderMatch) {
return elementA.index() - elementB.index();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册