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

findClosest

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