Allow multiple unsaved empty buffers to be opened

Fixes #1600
This commit is contained in:
Nathan Sobo
2014-03-01 14:40:48 -08:00
parent d6a9a0b15f
commit 7cc68f59a7
2 changed files with 18 additions and 8 deletions

View File

@@ -14,14 +14,24 @@ describe "Workspace", ->
describe "when the 'searchAllPanes' option is false (default)", ->
describe "when called without a uri", ->
it "adds and activates an empty editor on the active pane", ->
editor = null
[editor1, editor2] = []
waitsForPromise ->
workspace.open().then (o) -> editor = o
workspace.open().then (editor) -> editor1 = editor
runs ->
expect(editor.getPath()).toBeUndefined()
expect(workspace.activePane.items).toEqual [editor]
expect(workspace.activePaneItem).toBe editor
expect(editor1.getPath()).toBeUndefined()
expect(workspace.activePane.items).toEqual [editor1]
expect(workspace.activePaneItem).toBe editor1
expect(workspace.activePane.activate).toHaveBeenCalled()
waitsForPromise ->
workspace.open().then (editor) -> editor2 = editor
runs ->
expect(editor2.getPath()).toBeUndefined()
expect(workspace.activePane.items).toEqual [editor1, editor2]
expect(workspace.activePaneItem).toBe editor2
expect(workspace.activePane.activate).toHaveBeenCalled()
describe "when called with a uri", ->

View File

@@ -73,7 +73,7 @@ class Workspace extends Model
# if the uri is already open (default: false)
#
# Returns a promise that resolves to the {Editor} for the file URI.
open: (uri='', options={}) ->
open: (uri, options={}) ->
searchAllPanes = options.searchAllPanes
split = options.split
uri = atom.project.resolve(uri)
@@ -112,8 +112,8 @@ class Workspace extends Model
openUriInPane: (uri, pane, options={}) ->
changeFocus = options.changeFocus ? true
item = pane.itemForUri(uri)
if uri
if uri?
item = pane.itemForUri(uri)
item ?= opener(atom.project.resolve(uri), options) for opener in @getOpeners() when !item
item ?= atom.project.open(uri, options)