Skip to content

Commit

Permalink
Remove redundant MRU function.
Browse files Browse the repository at this point in the history
  • Loading branch information
natalieogle committed Feb 28, 2016
1 parent fe52ce6 commit 3641cc0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 43 deletions.
2 changes: 1 addition & 1 deletion keymaps/darwin.cson
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
'cmd-alt-right': 'pane:show-next-item'
'ctrl-pageup': 'pane:show-previous-item'
'ctrl-pagedown': 'pane:show-next-item'
'ctrl-tab': 'pane:show-most-recently-used-item'
'ctrl-tab': 'pane:show-next-recently-used-item'
'ctrl-shift-tab': 'pane:show-previous-item'
'cmd-=': 'window:increase-font-size'
'cmd-+': 'window:increase-font-size'
Expand Down
2 changes: 1 addition & 1 deletion keymaps/linux.cson
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
'pagedown': 'core:page-down'
'backspace': 'core:backspace'
'shift-backspace': 'core:backspace'
'ctrl-tab': 'pane:show-most-recently-used-item'
'ctrl-tab': 'pane:show-next-recently-used-item'
'ctrl-shift-tab': 'pane:show-previous-item'
'ctrl-pageup': 'pane:show-previous-item'
'ctrl-pagedown': 'pane:show-next-item'
Expand Down
2 changes: 1 addition & 1 deletion keymaps/win32.cson
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
'pagedown': 'core:page-down'
'backspace': 'core:backspace'
'shift-backspace': 'core:backspace'
'ctrl-tab': 'pane:show-most-recently-used-item'
'ctrl-tab': 'pane:show-next-recently-used-item'
'ctrl-shift-tab': 'pane:show-previous-item'
'ctrl-pageup': 'pane:show-previous-item'
'ctrl-pagedown': 'pane:show-next-item'
Expand Down
41 changes: 12 additions & 29 deletions spec/pane-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -183,31 +183,6 @@ describe "Pane", ->
pane.activateItem(itemD, true)
expect(pane.getItems().map (item) -> item.name).toEqual ['A', 'B', 'D']


describe "::activateMostRecentlyUsedItem()", ->
it "sets the active item to the most recently used item", ->
pane = new Pane(paneParams(items: [new Item("A"), new Item("B"), new Item("C")]))
[item1, item2, item3] = pane.getItems()
pane.itemStack = []

pane.activateItem(item3)
expect(pane.getActiveItem()).toBe item3
pane.activateItem(item1)
expect(pane.getActiveItem()).toBe item1
pane.activateMostRecentlyUsedItem()
pane.stopMovingThroughStackAndMoveItemToEndOfStack()
expect(pane.getActiveItem()).toBe item3
pane.activateItem(item2)
expect(pane.getActiveItem()).toBe item2
pane.activateMostRecentlyUsedItem()
pane.stopMovingThroughStackAndMoveItemToEndOfStack()
expect(pane.getActiveItem()).toBe item3
expect(pane.itemStack[0]).toBe item1
pane.destroyItem(item3)
pane.activateMostRecentlyUsedItem()
pane.stopMovingThroughStackAndMoveItemToEndOfStack()
expect(pane.getActiveItem()).toBe item1

describe "::activateNextRecentlyUsedItem()", ->
it "sets the active item to the next item in the itemStack", ->
pane = new Pane(paneParams(items: [new Item("A"), new Item("B"), new Item("C"), new Item("D"), new Item("E")]))
Expand All @@ -216,20 +191,28 @@ describe "Pane", ->

pane.activateItem(item4)
expect(pane.getActiveItem()).toBe item4
pane.activateMostRecentlyUsedItem()
pane.activateNextRecentlyUsedItem()
expect(pane.getActiveItem()).toBe item5
pane.activateNextRecentlyUsedItem()
expect(pane.getActiveItem()).toBe item2
pane.activateNextRecentlyUsedItem()
pane.stopMovingThroughStackAndMoveItemToEndOfStack()
expect(pane.getActiveItem()).toBe item1
pane.activateNextRecentlyUsedItem()
expect(pane.getActiveItem()).toBe item3
expect(pane.itemStack[4]).toBe item1
pane.activateNextRecentlyUsedItem()
expect(pane.getActiveItem()).toBe item4
pane.activateNextRecentlyUsedItem()
expect(pane.getActiveItem()).toBe item5
pane.activateNextRecentlyUsedItem()
expect(pane.getActiveItem()).toBe item2
pane.activateNextRecentlyUsedItem()
expect(pane.getActiveItem()).toBe item3
pane.activateNextRecentlyUsedItem()
expect(pane.getActiveItem()).toBe item1
pane.activateNextRecentlyUsedItem()
pane.stopMovingThroughStackAndMoveItemToEndOfStack()
expect(pane.itemStack[4]).toBe item5
expect(pane.getActiveItem()).toBe item4
expect(pane.itemStack[4]).toBe item4

describe "::activateNextItem() and ::activatePreviousItem()", ->
it "sets the active item to the next/previous item, looping around at either end", ->
Expand Down
17 changes: 7 additions & 10 deletions src/pane.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -323,21 +323,18 @@ class Pane extends Model
itemAtIndex: (index) ->
@items[index]

# Makes the most recently used item active.
activateMostRecentlyUsedItem: ->
if @items.length > 1
@itemStackIndex = @itemStack.length - 1
@activateNextRecentlyUsedItem()

# Makes the next item in the itemStack active.
activateNextRecentlyUsedItem: ->
@itemStackIndex = @itemStackIndex - 1
nextRecentlyUsedItem = @itemStack[@itemStackIndex]
@setActiveItem(nextRecentlyUsedItem, modifyStack: false)
@itemStackIndex = @itemStack.length if @itemStackIndex is 0
if @items.length > 1
@itemStackIndex = @itemStack.length - 1 unless @itemStackIndex?
@itemStackIndex = @itemStackIndex - 1
nextRecentlyUsedItem = @itemStack[@itemStackIndex]
@setActiveItem(nextRecentlyUsedItem, modifyStack: false)
@itemStackIndex = @itemStack.length if @itemStackIndex is 0

# Moves the active item to the end of the itemStack once the ctrl key is lifted
stopMovingThroughStackAndMoveItemToEndOfStack: ->
delete @itemStackIndex
@addItemToStack(@activeItem)

# Public: Makes the next item active.
Expand Down
2 changes: 1 addition & 1 deletion src/register-default-commands.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = ({commandRegistry, commandInstaller, config}) ->
commandRegistry.add 'atom-workspace',
'pane:show-most-recently-used-item': -> @getModel().getActivePane().activateMostRecentlyUsedItem()
'pane:show-next-recently-used-item': -> @getModel().getActivePane().activateNextRecentlyUsedItem()
'pane:show-next-item': -> @getModel().getActivePane().activateNextItem()
'pane:show-previous-item': -> @getModel().getActivePane().activatePreviousItem()
'pane:show-item-1': -> @getModel().getActivePane().activateItemAtIndex(0)
Expand Down

0 comments on commit 3641cc0

Please sign in to comment.