Write focusNext/PreviousPane in terms of activateNext/PreviousPane

"Activate" is the model level equivalent of focus.
This commit is contained in:
Nathan Sobo 2014-01-14 11:15:14 -07:00
parent 0d66c68fe8
commit 4a7b43f609
5 changed files with 20 additions and 22 deletions

View File

@ -42,7 +42,7 @@ describe "PaneContainerView", ->
describe ".focusPreviousPane()", ->
it "focuses the pane preceding the focused pane or the last pane if no pane has focus", ->
container.attachToDom()
$(document.body).focus() # clear focus
container.getPanes()[0].focus() # activate first pane
container.focusPreviousPane()
expect(pane3.activeItem).toMatchSelector ':focus'

View File

@ -106,22 +106,7 @@ class PaneContainerView extends View
@viewForModel(@model.paneForUri(uri))
focusNextPane: ->
panes = @getPanes()
if panes.length > 1
currentIndex = panes.indexOf(@getFocusedPane())
nextIndex = (currentIndex + 1) % panes.length
panes[nextIndex].focus()
true
else
false
@model.activateNextPane()
focusPreviousPane: ->
panes = @getPanes()
if panes.length > 1
currentIndex = panes.indexOf(@getFocusedPane())
previousIndex = currentIndex - 1
previousIndex = panes.length - 1 if previousIndex < 0
panes[previousIndex].focus()
true
else
false
@model.activatePreviousPane()

View File

@ -49,8 +49,20 @@ class PaneContainer extends Model
currentIndex = panes.indexOf(@activePane)
nextIndex = (currentIndex + 1) % panes.length
panes[nextIndex].activate()
true
else
@activePane = null
false
activatePreviousPane: ->
panes = @getPanes()
if panes.length > 1
currentIndex = panes.indexOf(@activePane)
previousIndex = currentIndex - 1
previousIndex = panes.length - 1 if previousIndex < 0
panes[previousIndex].activate()
true
else
false
onRootChanged: (root) =>
@unsubscribe(@previousRoot) if @previousRoot?

View File

@ -218,10 +218,10 @@ class WorkspaceView extends View
@panes.getActiveView()
# Public: Focuses the previous pane by id.
focusPreviousPane: -> @panes.focusPreviousPane()
focusPreviousPane: -> @model.activatePreviousPane()
# Public: Focuses the next pane by id.
focusNextPane: -> @panes.focusNextPane()
focusNextPane: -> @model.activateNextPane()
# Public:
#

View File

@ -12,7 +12,8 @@ class Workspace extends Model
Serializable.includeInto(this)
@delegatesProperty 'activePane', 'activePaneItem', toProperty: 'paneContainer'
@delegatesMethod 'getPanes', 'saveAll', toProperty: 'paneContainer'
@delegatesMethod 'getPanes', 'saveAll', 'activateNextPane', 'activatePreviousPane',
toProperty: 'paneContainer'
@properties
paneContainer: -> new PaneContainer