Skip to content

Commit

Permalink
refactor closeTabsForFile to separate the file enumeration and the ta…
Browse files Browse the repository at this point in the history
…b closing parts. This is now a little less efficient, as all files are listed, even the not opened ones, as opposed to only processing opened files straight away. It shouldn't matter with expected project sizes
  • Loading branch information
SillyFreak committed May 16, 2020
1 parent 6c953fe commit f0a6492
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/components/ide/Ide/Ide.js
Expand Up @@ -963,25 +963,32 @@ class Ide extends React.Component<PropTypes, StateTypes> {
}
}

closeTabsForFile(root: FileReference) {
const nodes = this.getNodes();

const close = (file: FileReference) => {
if (file.file.isDirectory()) {
closeTabsForFile(file: FileReference) {
// list all file paths below the given file/directory
const pathsToClose = [];
function listPaths(current: FileReference) {
if (current.file.isDirectory()) {
// $FlowExpectError
const dir: DirReference = file;
const dir: DirReference = current;
dir.file.contents.forEach(child =>
close({ path: `${dir.path}/${child.name}`, file: child }),
listPaths({ path: `${dir.path}/${child.name}`, file: child }),
);
} else if (file.path in nodes) {
} else {
pathsToClose.push(current.path);
}
}
listPaths(file);

// close those paths that are open
const nodes = this.getNodes();
pathsToClose.forEach(path => {
if (path in nodes) {
this.dispatch({
type: 'LAYOUT',
layoutAction: FlexLayout.Actions.deleteTab(file.path),
layoutAction: FlexLayout.Actions.deleteTab(path),
});
}
};

close(root);
});
}

render() {
Expand Down

0 comments on commit f0a6492

Please sign in to comment.