diff --git a/spec/extensions/tree-view-spec.coffee b/spec/extensions/tree-view-spec.coffee index 7d98dbaec..066b0e3b0 100644 --- a/spec/extensions/tree-view-spec.coffee +++ b/spec/extensions/tree-view-spec.coffee @@ -314,7 +314,7 @@ describe "TreeView", -> afterEach -> expect(treeView.find('.selected').length).toBeLessThan 2 - describe "move-down", -> + describe "core:move-down", -> describe "when a collapsed directory is selected", -> it "skips to the next directory", -> treeView.root.find('.directory:eq(0)').click() @@ -408,6 +408,33 @@ describe "TreeView", -> treeView.trigger 'core:move-up' expect(treeView.root).toHaveClass 'selected' + describe "core:move-to-top", -> + it "scrolls to the top", -> + treeView.height(100) + treeView.attachToDom() + $(element).view().expand() for element in treeView.find('.directory') + expect(treeView.prop('scrollHeight')).toBeGreaterThan treeView.outerHeight() + + expect(treeView.scrollTop()).toBe 0 + + entryCount = treeView.find(".entry").length + _.times entryCount, -> treeView.moveDown() + expect(treeView.scrollTop()).toBeGreaterThan 0 + + treeView.trigger 'core:move-to-top' + expect(treeView.scrollTop()).toBe 0 + + describe "core:move-to-bottom", -> + it "scrolls to the bottom", -> + treeView.height(100) + treeView.attachToDom() + $(element).view().expand() for element in treeView.find('.directory') + expect(treeView.prop('scrollHeight')).toBeGreaterThan treeView.outerHeight() + + expect(treeView.scrollTop()).toBe 0 + treeView.trigger 'core:move-to-bottom' + expect(treeView.scrollBottom()).toBe treeView.prop('scrollHeight') + describe "movement outside of viewable region", -> it "scrolls the tree view to the selected item", -> treeView.height(100) diff --git a/src/extensions/tree-view/tree-view.coffee b/src/extensions/tree-view/tree-view.coffee index 27588cced..aadae3536 100644 --- a/src/extensions/tree-view/tree-view.coffee +++ b/src/extensions/tree-view/tree-view.coffee @@ -48,6 +48,8 @@ class TreeView extends View @on 'click', '.entry', (e) => @entryClicked(e) @on 'core:move-up', => @moveUp() @on 'core:move-down', => @moveDown() + @on 'core:move-to-top', => @scrollToTop() + @on 'core:move-to-bottom', => @scrollToBottom() @on 'tree-view:expand-directory', => @expandDirectory() @on 'tree-view:collapse-directory', => @collapseDirectory() @on 'tree-view:open-selected-entry', => @openSelectedEntry(true) diff --git a/src/stdlib/jquery-extensions.coffee b/src/stdlib/jquery-extensions.coffee index adf11ea32..65f34d115 100644 --- a/src/stdlib/jquery-extensions.coffee +++ b/src/stdlib/jquery-extensions.coffee @@ -6,6 +6,12 @@ $.fn.scrollBottom = (newValue) -> else @scrollTop() + @height() +$.fn.scrollToTop = -> + @scrollTop(0) + +$.fn.scrollToBottom = -> + @scrollTop(@prop('scrollHeight')) + $.fn.scrollRight = (newValue) -> if newValue? @scrollLeft(newValue - @width())