Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove sub-folders from open folders array when closing it's parent #130

Merged
merged 6 commits into from
May 19, 2016
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions public/app/components/fileTree/fileTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,18 @@ angular.module('kibibitCodeEditor')
var folder;
if (treeNode.type == 'directory') {
folder = treeNode;
var directoryIndex = vm.expandedNodes.indexOf(folder);
var isDirectoryOpen = directoryIndex > -1;
if (isDirectoryOpen) {
// contract directory
vm.expandedNodes.splice(directoryIndex, 1);
var folderIndex = vm.expandedNodes.indexOf(folder);
var isFolderOpen = folderIndex > -1;

if (isFolderOpen) {
closeFolder(folder);
} else {
FolderService.getFolder(folder.path, function(folderContent) {
folder.children = folderContent.data.children;
});
vm.expandedNodes.push(folder);
}

if (vm.options.selectionMode == 'folder') {
vm.selection = folder.path;
}
Expand All @@ -78,5 +79,14 @@ angular.module('kibibitCodeEditor')
}
}
};

var closeFolder = function(folder) {
var nameIndex = folder.path.indexOf(folder.name);
var pathPrefix = folder.path.substr(0, nameIndex) + folder.name;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Illegal trailing whitespace

Copy link
Member Author

@ortichon ortichon May 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@houndci-bot
good boy, now work again!

vm.expandedNodes = vm.expandedNodes.filter(function(node) {
return node.path.indexOf(pathPrefix) === -1;
});
};
}]);