提交 7b4d5048 编写于 作者: I isidor

findClosest

fixes #29718
上级 6d09da44
......@@ -1270,7 +1270,7 @@ export class CompareResourcesAction extends Action {
// Check if file was deleted or moved meanwhile (explorer only)
if (this.tree) {
const input: FileStat | Model = this.tree.getInput();
const exists = input instanceof Model ? input.findFirst(globalResourceToCompare) : input.find(globalResourceToCompare);
const exists = input instanceof Model ? input.findClosest(globalResourceToCompare) : input.find(globalResourceToCompare);
if (!exists) {
globalResourceToCompare = null;
return false;
......
......@@ -328,7 +328,7 @@ export class ExplorerView extends CollapsibleView {
lastActiveFileResource = URI.parse(this.settings[ExplorerView.MEMENTO_LAST_ACTIVE_FILE_RESOURCE]);
}
if (lastActiveFileResource && this.isCreated && this.model.findFirst(lastActiveFileResource)) {
if (lastActiveFileResource && this.isCreated && this.model.findClosest(lastActiveFileResource)) {
this.editorService.openEditor({ resource: lastActiveFileResource, options: { revealIfVisible: true } }).done(null, errors.onUnexpectedError);
return refreshPromise;
......@@ -606,8 +606,8 @@ export class ExplorerView extends CollapsibleView {
}
// Compute if parent is visible and added file not yet part of it
const parentStat = this.model.findFirst(URI.file(parent));
if (parentStat && parentStat.isDirectoryResolved && !this.model.findFirst(change.resource)) {
const parentStat = this.model.findClosest(URI.file(parent));
if (parentStat && parentStat.isDirectoryResolved && !this.model.findClosest(change.resource)) {
return true;
}
......@@ -624,7 +624,7 @@ export class ExplorerView extends CollapsibleView {
continue; // out of workspace file
}
if (this.model.findFirst(del.resource)) {
if (this.model.findClosest(del.resource)) {
return true;
}
}
......@@ -765,7 +765,7 @@ export class ExplorerView extends CollapsibleView {
// If it is a brand new tree just expand elements from memento
const expanded = this.explorerViewer.getExpandedElements();
const statsToExpand = expanded.length ? [this.model.roots[0]].concat(expanded) :
targetsToExpand.map(expand => this.model.findFirst(expand));
targetsToExpand.map(expand => this.model.findClosest(expand));
// Display roots only when there is more than 1 root
// Make sure to expand all folders that where expanded in the previous session
......@@ -826,7 +826,7 @@ export class ExplorerView extends CollapsibleView {
return TPromise.as(null);
}
const fileStat = this.model.findFirst(resource);
const fileStat = this.model.findClosest(resource);
if (fileStat) {
return this.doSelect(fileStat, reveal);
}
......
......@@ -35,19 +35,25 @@ export class Model {
}
/**
* Returns a child stat from this stat that matches with the provided path.
* Returns an array of child stat from this stat that matches with the provided path.
* Starts matching from the first root.
* Will return "null" in case the child does not exist.
* Will return empty array in case the FileStat does not exist.
*/
public findAll(resource: URI): FileStat[] {
return this.roots.map(root => root.find(resource)).filter(stat => !!stat);
}
public findFirst(resource: URI): FileStat {
for (let root of this.roots) {
const result = root.find(resource);
if (result) {
return result;
/**
* Returns a FileStat that matches the passed resource.
* In case multiple FileStat are matching the resource (same folder opened multiple times) returns the FileStat that has the closest root.
* Will return null in case the FileStat does not exist.
*/
public findClosest(resource: URI): FileStat {
const rootUri = this.contextService.getRoot(resource);
if (rootUri) {
const root = this.roots.filter(r => r.resource.toString() === rootUri.toString()).pop();
if (root) {
return root.find(resource);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册