Allow paths to be selected

This will allow them to be navigated to with the
keyboard and collapsed or expanded.
This commit is contained in:
Kevin Sawicki
2013-02-13 21:42:39 -08:00
parent 61481fc1d8
commit 4088d33dc9
3 changed files with 35 additions and 31 deletions

View File

@@ -18,6 +18,7 @@ class OperationView extends View
false
@on 'mousedown', (e) =>
@executeOperation()
@previewList.find('.selected').removeClass('selected')
@addClass('selected')
executeOperation: ->

View File

@@ -4,13 +4,13 @@ ScrollView = require 'scroll-view'
_ = require 'underscore'
fs = require 'fs'
PathView = require './path-view'
OperationView = require './operation-view'
module.exports =
class PreviewList extends ScrollView
@content: ->
@ol class: 'preview-list', tabindex: -1
selectedOperationIndex: 0
operations: null
initialize: (@rootView) ->
@@ -19,9 +19,6 @@ class PreviewList extends ScrollView
@on 'core:move-down', => @selectNextOperation(); false
@on 'core:move-up', => @selectPreviousOperation(); false
@on 'mousedown', 'li.operation', (e) =>
@setSelectedOperationIndex(parseInt($(e.target).closest('li').data('index')))
@command 'command-panel:collapse-all', => @collapseAllPaths()
@command 'command-panel:expand-all', => @expandAllPaths()
@@ -46,8 +43,8 @@ class PreviewList extends ScrollView
for path, operations of operationsByPath
@append new PathView({path, operations, previewList: this})
@setSelectedOperationIndex(0)
@show()
@find('.operation:first').addClass('selected')
@setLineNumberWidth()
setLineNumberWidth: ->
@@ -58,25 +55,29 @@ class PreviewList extends ScrollView
lineNumbers.width(maxWidth)
selectNextOperation: ->
@setSelectedOperationIndex(@selectedOperationIndex + 1)
selectedView = @find('.selected').view()
if selectedView instanceof PathView
nextView = selectedView.find('.operation:first')
else
nextView = selectedView.next().view() ? selectedView.closest('.path').next().view()
if nextView?
selectedView.removeClass('selected')
nextView.addClass('selected')
@scrollToElement(nextView)
selectPreviousOperation: ->
@setSelectedOperationIndex(@selectedOperationIndex - 1)
selectedView = @find('.selected').view()
setSelectedOperationIndex: (index, scrollToOperation=true) ->
index = Math.max(0, index)
index = Math.min(@operations.length - 1, index)
@find('li.selected').removeClass('selected')
element = @find("ul.matches li.operation:eq(#{index})")
element.addClass('selected')
if selectedView instanceof PathView
previousView = selectedView.prev().find('.operation:last').view()
else
previousView = selectedView.prev().view() ? selectedView.closest('.path').view()
if scrollToOperation
if index is 0
@scrollToTop()
else
@scrollToElement(element)
@selectedOperationIndex = index
if previousView?
selectedView.removeClass('selected')
previousView.addClass('selected')
@scrollToElement(previousView)
getPathCount: ->
_.keys(_.groupBy(@operations, (operation) -> operation.getPath())).length
@@ -89,7 +90,7 @@ class PreviewList extends ScrollView
@operations = null
getSelectedOperation: ->
@operations[@selectedOperationIndex]
@find('.operation.selected').view()?.operation
scrollToElement: (element) ->
top = @scrollTop() + element.offset().top - @offset().top
@@ -101,9 +102,11 @@ class PreviewList extends ScrollView
scrollToBottom: ->
super()
@setSelectedOperationIndex(Infinity, false)
@find('.selected').removeClass('selected')
@find('.operation:last').addClass('selected')
scrollToTop: ->
super()
@setSelectedOperationIndex(0, false)
@find('.selected').removeClass('selected')
@find('.path:first').addClass('selected')

View File

@@ -395,29 +395,29 @@ describe "CommandPanel", ->
expect(previewList.find('li.operation:eq(1)')).toHaveClass 'selected'
expect(previewList.getSelectedOperation()).toBe previewList.getOperations()[1]
_.times previewList.getOperations().length - 2, -> previewList.trigger 'core:move-down'
_.times previewList.getOperations().length + previewList.getPathCount(), -> previewList.trigger 'core:move-down'
expect(previewList.find("li.operation:last")).toHaveClass 'selected'
expect(previewList.getSelectedOperation()).toBe _.last(previewList.getOperations())
expect(previewList.scrollBottom()).toBeCloseTo previewList.prop('scrollHeight'), -1
_.times previewList.getOperations().length, -> previewList.trigger 'core:move-up'
_.times previewList.getOperations().length + previewList.getPathCount(), -> previewList.trigger 'core:move-up'
expect(previewList.scrollTop()).toBe 0
it "doesn't bubble up the event and the command panel text doesn't change", ->
rootView.attachToDom()
commandPanel.miniEditor.setText "command"
previewList.focus()
previewList.trigger 'core:move-up'
expect(previewList.find('li.operation:eq(0)')).toHaveClass 'selected'
expect(commandPanel.miniEditor.getText()).toBe 'command'
previewList.trigger 'core:move-down'
expect(previewList.find('li.operation:eq(1)')).toHaveClass 'selected'
expect(commandPanel.miniEditor.getText()).toBe 'command'
previewList.trigger 'core:move-up'
expect(previewList.find('li.operation:eq(0)')).toHaveClass 'selected'
expect(commandPanel.miniEditor.getText()).toBe 'command'
describe "when move-to-top and move-to-bottom are triggered on the preview list", ->
it "selects the first/last operation", ->
it "selects the first path or last operation", ->
rootView.attachToDom()
expect(previewList.getOperations().length).toBeGreaterThan 0
expect(previewList.find('li.operation:eq(0)')).toHaveClass 'selected'
@@ -428,8 +428,8 @@ describe "CommandPanel", ->
expect(previewList.getSelectedOperation()).toBe _.last(previewList.getOperations())
previewList.trigger 'core:move-to-top'
expect(previewList.find('li.operation:eq(0)')).toHaveClass 'selected'
expect(previewList.getSelectedOperation()).toBe previewList.getOperations()[0]
expect(previewList.find('li.path:eq(0)')).toHaveClass 'selected'
expect(previewList.getSelectedOperation()).toBeUndefined()
describe "when core:confirm is triggered on the preview list", ->
it "opens the operation's buffer, selects and scrolls to the search result, and refocuses the preview list", ->