Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Improve behavior of TreeView::moveUp() with nested directories #1069
Description of the Change
The previous moveUp() behavior checked whether the entry directly before the currently selected entry was an expanded directory, and if so, it selected the last child of that directory. That was perfectly fine for most cases, but if that last child entry was also an expanded directory, the moveUp() command would simply select the child directory instead of selecting its last entry. This pull request changes that behavior so that tree-view will recursively check whether the previous entry is an expanded directory, then check whether the last entry in that directory is too, and so on, before finally selecting the first entry it encounters that is either not a directory or not expanded.
An earlier revision of this change didn't explicitly check whether previousEntry was a directory or was expanded, and it also called TreeView::selectEntry() with each recursive iteration. That didn't seem to break anything, but it probably wasn't a great idea.
Keyboard navigation of the tree-view will be a lot nicer, especially for users who have the "sort directories before files" option turned off.
I can't foresee any.
referenced this pull request
Jun 26, 2018
This merges cleanly with master, and based on my limited user testing I'd say it's working fine,
Edit: I just needed to run
@synthetiv what do you think about the following diff?
diff --git a/lib/tree-view.coffee b/lib/tree-view.coffee index d72b91e..d9855cf 100644 --- a/lib/tree-view.coffee +++ b/lib/tree-view.coffee @@ -421,8 +421,6 @@ class TreeView selectedEntry = @selectedEntry() if selectedEntry? if previousEntry = @previousEntry(selectedEntry) - while previousEntry.classList.contains('directory', 'expanded') and previousEntry.entries.children.length > 0 - previousEntry = _.last(previousEntry.entries.children) @selectEntry(previousEntry) else @selectEntry(selectedEntry.parentElement.closest('.directory')) @@ -445,12 +443,21 @@ class TreeView return null previousEntry: (entry) -> - currentEntry = entry - while currentEntry? - currentEntry = currentEntry.previousSibling - if currentEntry?.matches('.entry') - return currentEntry - return null + previousEntry = entry.previousSibling + while previousEntry? and not previousEntry.matches('.entry') + previousEntry = previousEntry.previousSibling + + return null unless previousEntry? + + # If the previous entry is an expanded directory, + # we need to select the last entry in that directory, + # not the directory itself + if previousEntry.matches('.directory.expanded') + entries = previousEntry.querySelectorAll('.entry') + if entries.length > 0 + return entries[entries.length - 1] + + return previousEntry expandDirectory: (isRecursive=false) -> selectedEntry = @selectedEntry()
This adjusts the
In addition, can you add a test for the case when there is an expanded directory that contains no children entries?