Undo last closed tab

This commit is contained in:
Jon Rohan 2013-01-25 20:37:31 -08:00 committed by Kevin Sawicki
parent 1ee1fa02ba
commit c43a1e5ce5
3 changed files with 31 additions and 1 deletions

View File

@ -151,6 +151,13 @@ describe "Editor", ->
expect(otherEditSession.buffer.subscriptionCount()).toBe 0
describe "when 'close' is triggered", ->
it "adds a closed session path to the array", ->
editor.edit(rootView.project.buildEditSessionForPath())
editSession = editor.activeEditSession
expect(editor.closedEditSessions.length).toBe 0
editor.trigger "core:close"
expect(editor.closedEditSessions.length).toBe 1
it "closes the active edit session and loads next edit session", ->
editor.edit(rootView.project.buildEditSessionForPath())
editSession = editor.activeEditSession
@ -2664,3 +2671,15 @@ describe "Editor", ->
editor.moveEditSessionToEditor(0, rightEditor, 0)
expect(rightEditor.editSessions[0].getPath()).toBe jsPath
expect(rightEditor.editSessions[1].getPath()).toBe txtPath
describe "when editor:undo-close-session is triggered", ->
it "opens the closed session back up", ->
rootView.open('sample.txt')
expect(editor.getPath()).toBe require.resolve('fixtures/sample.txt')
expect(editor.closedEditSessions.length).toBe 0
editor.trigger "core:close"
expect(editor.getPath()).toBe require.resolve('fixtures/sample.js')
expect(editor.closedEditSessions.length).toBe 1
editor.trigger 'editor:undo-close-session'
expect(editor.getPath()).toBe require.resolve('fixtures/sample.txt')
expect(editor.closedEditSessions.length).toBe 0

View File

@ -48,6 +48,7 @@ class Editor extends View
lineCache: null
isFocused: false
activeEditSession: null
closedEditSessions: null
editSessions: null
attached: false
lineOverdraw: 10
@ -74,6 +75,7 @@ class Editor extends View
@cursorViews = []
@selectionViews = []
@editSessions = []
@closedEditSessions = []
@pendingChanges = []
@newCursors = []
@newSelections = []
@ -187,6 +189,7 @@ class Editor extends View
'editor:move-line-up': @moveLineUp
'editor:move-line-down': @moveLineDown
'editor:duplicate-line': @duplicateLine
'editor:undo-close-session': @undoDestroySession
documentation = {}
for name, method of editorBindings
@ -470,6 +473,9 @@ class Editor extends View
getBuffer: -> @activeEditSession.buffer
undoDestroySession: ->
@rootView().open(@closedEditSessions.pop(), true) unless @closedEditSessions.length == 0
destroyActiveEditSession: ->
@destroyEditSessionIndex(@getActiveEditSessionIndex())
@ -477,7 +483,9 @@ class Editor extends View
return if @mini
editSession = @editSessions[index]
destroySession = ->
destroySession = =>
path = editSession.getPath()
@closedEditSessions.push(path) unless @closedEditSessions.indexOf(path) > -1
editSession.destroy()
callback?(index)

View File

@ -1,3 +1,6 @@
'#root-view':
'meta-T': 'editor:undo-close-session'
'.editor':
'meta-s': 'editor:save'
'meta-S': 'editor:save-as'