meta-w closes edit sessions until there are none left, then it closes the editor

This commit is contained in:
Corey Johnson 2012-06-07 10:21:16 -07:00
parent e167afd794
commit 481ec16485
2 changed files with 24 additions and 7 deletions

View File

@ -2685,8 +2685,16 @@ describe "Editor", ->
editor.splitRight()
describe "when 'close' is triggered", ->
it "calls remove on the editor if mini is false", ->
it "closes active edit session and loads next edit session", ->
editor.setBuffer(new Buffer())
spyOn(editor, "remove")
editor.trigger "close"
expect(editor.remove).not.toHaveBeenCalled()
expect(editor.buffer).toBe buffer
it "calls remove on the editor if there is one edit session and mini is false", ->
expect(editor.mini).toBeFalsy()
expect(editor.editSessions.length).toBe 1
spyOn(editor, 'remove')
editor.trigger 'close'
expect(editor.remove).toHaveBeenCalled()

View File

@ -220,7 +220,6 @@ class Editor extends View
else
@gutter.addClass('drop-shadow')
afterAttach: (onDom) ->
return if @attached or not onDom
@attached = true
@ -343,6 +342,14 @@ class Editor extends View
return index if editSession.buffer == buffer
null
removeActiveEditSession: ->
if @editSessions.length == 1
@remove()
else
editSession = @activeEditSession
@loadPreviousEditSession()
_.remove(@editSessions, editSession)
loadNextEditSession: ->
nextIndex = (@activeEditSessionIndex + 1) % @editSessions.length
@setActiveEditSessionIndex(nextIndex)
@ -367,6 +374,9 @@ class Editor extends View
@renderLines()
@setCursorScreenPosition(@activeEditSession.cursorScreenPosition ? [0, 0])
destroyEditSessions: ->
session.destroy() for session in @editSessions
setScrollPositionFromActiveEditSession: ->
@scrollTop(@activeEditSession.scrollTop ? 0)
@scrollView.scrollLeft(@activeEditSession.scrollLeft ? 0)
@ -739,8 +749,11 @@ class Editor extends View
@parent('.pane').view()
close: ->
@remove() unless @mini
return if @mini
@removeActiveEditSession()
unsubscribeFromBuffer: ->
@buffer.off ".editor#{@id}"
remove: (selector, keepData) ->
return super if keepData
@ -755,11 +768,7 @@ class Editor extends View
if @pane() then @pane().remove() else super
rootView?.focus()
unsubscribeFromBuffer: ->
@buffer.off ".editor#{@id}"
destroyEditSessions: ->
session.destroy() for session in @editSessions
stateForScreenRow: (row) ->
@renderer.lineForRow(row).state