mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Add core:move-to-top and core:move-to-bottom support to tree view
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user