mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Merge pull request #135 from github/undo-tab-close
Restore last closed tab
This commit is contained in:
@@ -151,6 +151,16 @@ 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 0
|
||||
editor.edit(rootView.project.buildEditSessionForPath(rootView.project.resolve('sample.txt')))
|
||||
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
|
||||
@@ -247,6 +257,14 @@ describe "Editor", ->
|
||||
editor.insertText("def\n")
|
||||
expect(editor.lineElementForScreenRow(0).text()).toBe 'def'
|
||||
|
||||
it "removes the opened session from the closed sessions array", ->
|
||||
editor.edit(rootView.project.buildEditSessionForPath('sample.txt'))
|
||||
expect(editor.closedEditSessions.length).toBe 0
|
||||
editor.trigger "core:close"
|
||||
expect(editor.closedEditSessions.length).toBe 1
|
||||
editor.edit(rootView.project.buildEditSessionForPath('sample.txt'))
|
||||
expect(editor.closedEditSessions.length).toBe 0
|
||||
|
||||
describe "switching edit sessions", ->
|
||||
[session0, session1, session2] = []
|
||||
|
||||
@@ -2664,3 +2682,25 @@ 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", ->
|
||||
describe "when an edit session is opened back up after it is closed", ->
|
||||
it "is removed from the undo stack and not reopened when the event is triggered", ->
|
||||
rootView.open('sample.txt')
|
||||
expect(editor.getPath()).toBe fixturesProject.resolve('sample.txt')
|
||||
editor.trigger "core:close"
|
||||
expect(editor.closedEditSessions.length).toBe 1
|
||||
rootView.open('sample.txt')
|
||||
expect(editor.closedEditSessions.length).toBe 0
|
||||
editor.trigger 'editor:undo-close-session'
|
||||
expect(editor.getPath()).toBe fixturesProject.resolve('sample.txt')
|
||||
|
||||
it "opens the closed session back up at the previous index", ->
|
||||
rootView.open('sample.txt')
|
||||
editor.loadPreviousEditSession()
|
||||
expect(editor.getPath()).toBe fixturesProject.resolve('sample.js')
|
||||
editor.trigger "core:close"
|
||||
expect(editor.getPath()).toBe fixturesProject.resolve('sample.txt')
|
||||
editor.trigger 'editor:undo-close-session'
|
||||
expect(editor.getPath()).toBe fixturesProject.resolve('sample.js')
|
||||
expect(editor.getActiveEditSessionIndex()).toBe 0
|
||||
|
||||
@@ -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
|
||||
@@ -464,12 +467,22 @@ class Editor extends View
|
||||
pushEditSession: (editSession) ->
|
||||
index = @editSessions.length
|
||||
@editSessions.push(editSession)
|
||||
@closedEditSessions = @closedEditSessions.filter ({path})->
|
||||
path isnt editSession.getPath()
|
||||
editSession.on 'destroyed', => @editSessionDestroyed(editSession)
|
||||
@trigger 'editor:edit-session-added', [editSession, index]
|
||||
index
|
||||
|
||||
getBuffer: -> @activeEditSession.buffer
|
||||
|
||||
undoDestroySession: ->
|
||||
return unless @closedEditSessions.length > 0
|
||||
|
||||
{path, index} = @closedEditSessions.pop()
|
||||
@rootView().open(path)
|
||||
activeIndex = @getActiveEditSessionIndex()
|
||||
@moveEditSessionToIndex(activeIndex, index) if index < activeIndex
|
||||
|
||||
destroyActiveEditSession: ->
|
||||
@destroyEditSessionIndex(@getActiveEditSessionIndex())
|
||||
|
||||
@@ -477,7 +490,9 @@ class Editor extends View
|
||||
return if @mini
|
||||
|
||||
editSession = @editSessions[index]
|
||||
destroySession = ->
|
||||
destroySession = =>
|
||||
path = editSession.getPath()
|
||||
@closedEditSessions.push({path, index}) if path
|
||||
editSession.destroy()
|
||||
callback?(index)
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
'body':
|
||||
'meta-T': 'editor:undo-close-session'
|
||||
|
||||
'.editor':
|
||||
'meta-s': 'editor:save'
|
||||
'meta-S': 'editor:save-as'
|
||||
|
||||
Reference in New Issue
Block a user