Rename ::makeActive to ::activate and focus panes when they're activated

This commit is contained in:
Nathan Sobo
2014-01-11 20:48:01 -07:00
parent f5bc71e559
commit 28b085be1c
9 changed files with 33 additions and 45 deletions

View File

@@ -19,7 +19,7 @@ describe "PaneContainerModel", ->
expect(pane3B.focused).toBe true
it "preserves the active pane across serialization, independent of focus", ->
pane3A.makeActive()
pane3A.activate()
expect(containerA.activePane).toBe pane3A
containerB = containerA.testSerialization()
@@ -37,20 +37,20 @@ describe "PaneContainerModel", ->
expect(container.activePane).toBe pane1
expect(pane1.active).toBe true
it "references the most pane on which ::makeActive was most recently called", ->
it "references the most pane on which ::activate was most recently called", ->
pane2 = pane1.splitRight()
pane2.makeActive()
pane2.activate()
expect(container.activePane).toBe pane2
expect(pane1.active).toBe false
expect(pane2.active).toBe true
pane1.makeActive()
pane1.activate()
expect(container.activePane).toBe pane1
expect(pane1.active).toBe true
expect(pane2.active).toBe false
it "is reassigned to the next pane if the current active pane is destroyed", ->
pane2 = pane1.splitRight()
pane2.makeActive()
pane2.activate()
pane2.destroy()
expect(container.activePane).toBe pane1
expect(pane1.active).toBe true

View File

@@ -249,7 +249,7 @@ describe "PaneContainer", ->
expect(activeItemChangedHandler).not.toHaveBeenCalled()
it "is triggered when the active pane is changed", ->
pane1.makeActive()
pane1.activate()
expect(activeItemChangedHandler.callCount).toBe 1
expect(activeItemChangedHandler.argsForCall[0][1]).toEqual item1a

View File

@@ -41,7 +41,7 @@ describe "Pane", ->
expect(pane.activeItem).toBe view2
it "triggers 'pane:active-item-changed' if the item isn't already the activeItem", ->
pane.makeActive()
pane.activate()
itemChangedHandler = jasmine.createSpy("itemChangedHandler")
container.on 'pane:active-item-changed', itemChangedHandler
@@ -447,24 +447,14 @@ describe "Pane", ->
paneToRight = pane.splitRight(pane.copyActiveItem())
container.attachToDom()
describe "when the removed pane is focused", ->
it "activates and focuses the next pane", ->
pane.focus()
describe "when the removed pane is active", ->
it "makes the next the next pane active and focuses it", ->
pane.activate()
pane.remove()
expect(paneToLeft.isActive()).toBeFalsy()
expect(paneToRight.isActive()).toBeTruthy()
expect(paneToRight).toMatchSelector ':has(:focus)'
describe "when the removed pane is active but not focused", ->
it "activates the next pane, but does not focus it", ->
$(document.activeElement).blur()
expect(pane).not.toMatchSelector ':has(:focus)'
pane.makeActive()
pane.remove()
expect(paneToLeft.isActive()).toBeFalsy()
expect(paneToRight.isActive()).toBeTruthy()
expect(paneToRight).not.toMatchSelector ':has(:focus)'
describe "when the removed pane is not active", ->
it "does not affect the active pane or the focus", ->
paneToLeft.focus()

View File

@@ -311,7 +311,6 @@ describe "WorkspaceView", ->
describe "when there is an active pane", ->
[pane1] = []
beforeEach ->
spyOn(Pane.prototype, 'focus').andCallFake -> @makeActive()
pane1 = atom.workspaceView.getActivePane()
it "creates a new pane and reuses the file when already open", ->
@@ -322,7 +321,7 @@ describe "WorkspaceView", ->
expect(pane2.itemForUri('b')).not.toBeFalsy()
expect(atom.workspaceView.panes.find('.pane-row .pane').toArray()).toEqual [pane1[0], pane2[0]]
pane1.focus()
pane1.activate()
expect(atom.workspaceView.getActivePane()[0]).toBe pane1[0]
atom.workspaceView.openSingletonSync('b', split: 'right')
@@ -346,7 +345,7 @@ describe "WorkspaceView", ->
expect(pane2.itemForUri('file1')).toBeFalsy()
expect(atom.workspaceView.panes.find('.pane-row .pane').toArray()).toEqual [pane1[0], pane2[0]]
pane2.focus()
pane2.activate()
expect(atom.workspaceView.getActivePane()[0]).toBe pane2[0]
atom.workspaceView.openSingletonSync('file1', split: 'left')

View File

@@ -34,12 +34,12 @@ class PaneContainerModel extends Model
getPanes: ->
@root?.getPanes() ? []
makeNextPaneActive: ->
activateNextPane: ->
panes = @getPanes()
if panes.length > 1
currentIndex = panes.indexOf(@activePane)
nextIndex = (currentIndex + 1) % panes.length
@activePane = panes[nextIndex]
panes[nextIndex].activate()
else
@activePane = null

View File

@@ -54,6 +54,8 @@ class PaneContainer extends View
view = @viewForModel(root)
@append(view)
focusedElement?.focus()
else
atom.workspaceView?.focus() if focusedElement?
onActivePaneItemChanged: (activeItem) =>
@trigger 'pane-container:active-pane-item-changed', [activeItem]
@@ -120,7 +122,6 @@ class PaneContainer extends View
panes[nextIndex].focus()
true
else
atom.workspaceView?.focus()
false
focusPreviousPane: ->

View File

@@ -34,7 +34,7 @@ class PaneModel extends Model
@subscribe @items.onRemoval (item, index) =>
@unsubscribe item if typeof item.on is 'function'
@makeActive() if params?.active
@activate() if params?.active
serializeParams: ->
items: compact(@items.map((item) -> item.serialize?()))
@@ -54,13 +54,15 @@ class PaneModel extends Model
focus: ->
@focused = true
@makeActive()
@activate() unless @isActive()
blur: ->
@focused = false
true # if this is called from an event handler, don't cancel it
makeActive: -> @container?.activePane = this
activate: ->
@container?.activePane = this
@emit 'activated'
getPanes: -> [this]
@@ -161,7 +163,7 @@ class PaneModel extends Model
# Private: Called by model superclass
destroyed: ->
@container.makeNextPaneActive() if @isActive()
@container.activateNextPane() if @isActive()
item.destroy?() for item in @items.slice()
# Public: Prompt the user to save the given item.
@@ -248,5 +250,5 @@ class PaneModel extends Model
when 'before' then @parent.insertChildBefore(this, newPane)
when 'after' then @parent.insertChildAfter(this, newPane)
newPane.makeActive()
newPane.activate()
newPane

View File

@@ -30,7 +30,7 @@ class Pane extends View
'moveItem', 'moveItemToPane', 'destroyItem', 'destroyItems', 'destroyActiveItem',
'destroyInactiveItems', 'saveActiveItem', 'saveActiveItemAs', 'saveItem', 'saveItemAs',
'saveItems', 'itemForUri', 'showItemForUri', 'promptToSaveItem', 'copyActiveItem',
'isActive', 'makeActive', toProperty: 'model'
'isActive', 'activate', toProperty: 'model'
previousActiveItem: null
@@ -55,6 +55,7 @@ class Pane extends View
@subscribe @model, 'item-moved', @onItemMoved
@subscribe @model, 'before-item-destroyed', @onBeforeItemDestroyed
@subscribe @model, 'item-destroyed', @onItemDestroyed
@subscribe @model, 'activated', @onActivated
@subscribe @model.$active, @onActiveStatusChanged
@subscribe this, 'focusin', => @model.focus()
@@ -99,6 +100,9 @@ class Pane extends View
@attached = true
@trigger 'pane:attached', [this]
onActivated: =>
@focus() unless @hasFocus()
onActiveStatusChanged: (active) =>
if active
@addClass('active')
@@ -123,13 +127,13 @@ class Pane extends View
return unless item?
isFocused = @is(':has(:focus)')
hasFocus = @hasFocus()
item.on? 'title-changed', @activeItemTitleChanged
view = @viewForItem(item)
@itemViews.children().not(view).hide()
@itemViews.append(view) unless view.parent().is(@itemViews)
view.show() if @attached
view.focus() if isFocused
view.focus() if hasFocus
@activeView = view
@trigger 'pane:active-item-changed', [item]
@@ -143,11 +147,6 @@ class Pane extends View
else if viewToRemove = @viewsByItem.get(item)
@viewsByItem.delete(item)
removingLastItem = @model.items.length is 0
hasFocus = @hasFocus()
@getContainer().focusNextPane() if hasFocus and removingLastItem
if viewToRemove?
viewToRemove.setModel?(null)
if destroyed
@@ -155,8 +154,6 @@ class Pane extends View
else
viewToRemove.detach()
# @focus() if hasFocus and not removingLastItem
@trigger 'pane:item-removed', [item, index]
onItemMoved: (item, newIndex) =>
@@ -202,7 +199,6 @@ class Pane extends View
@closest('.panes').view()
beforeRemove: ->
@getContainer()?.focusNextPane() if @hasFocus()
@model.destroy() unless @model.isDestroyed()
# Private:

View File

@@ -173,7 +173,7 @@ class WorkspaceView extends View
@itemOpened(editor)
activePane.showItem(editor)
activePane.focus() if changeFocus
activePane.activate() if changeFocus
@trigger "uri-opened"
editor
.catch (error) ->
@@ -208,7 +208,7 @@ class WorkspaceView extends View
@itemOpened(paneItem)
pane.focus() if changeFocus
pane.activate() if changeFocus
paneItem
openSingletonSync: (uri, {changeFocus, initialLine, split}={}) ->
@@ -219,7 +219,7 @@ class WorkspaceView extends View
if pane
paneItem = pane.itemForUri(uri)
pane.showItem(paneItem)
pane.focus() if changeFocus
pane.activate() if changeFocus
paneItem
else
@openSync(uri, {changeFocus, initialLine, split})