diff --git a/spec/atom-spec.coffee b/spec/atom-spec.coffee index 12d094428..8603f008b 100644 --- a/spec/atom-spec.coffee +++ b/spec/atom-spec.coffee @@ -152,3 +152,31 @@ describe "the `atom` global", -> loadSettings.initialPaths = [dir2, dir1] atom2 = Atom.loadOrCreate("editor") expect(atom2.state.stuff).toBe("cool") + + describe "openInitialEmptyEditorIfNecessary", -> + describe "when there are no paths set", -> + beforeEach -> + spyOn(atom, 'getLoadSettings').andReturn(initialPaths: []) + + it "opens an empty buffer", -> + spyOn(atom.workspace, 'open') + atom.openInitialEmptyEditorIfNecessary() + expect(atom.workspace.open).toHaveBeenCalledWith(null, {isInitialEmptyEditor: true}) + + describe "when there is already a buffer open", -> + beforeEach -> + waitsForPromise -> atom.workspace.open() + + it "does not open an empty buffer", -> + spyOn(atom.workspace, 'open') + atom.openInitialEmptyEditorIfNecessary() + expect(atom.workspace.open).not.toHaveBeenCalled() + + describe "when the project has a path", -> + beforeEach -> + spyOn(atom, 'getLoadSettings').andReturn(initialPaths: ['something']) + spyOn(atom.workspace, 'open') + + it "does not open an empty buffer", -> + atom.openInitialEmptyEditorIfNecessary() + expect(atom.workspace.open).not.toHaveBeenCalled() diff --git a/src/atom.coffee b/src/atom.coffee index 303b0cfe7..7f2626fa9 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -605,6 +605,8 @@ class Atom extends Model @setAutoHideMenuBar(newValue) @setAutoHideMenuBar(true) if @config.get('core.autoHideMenuBar') + @openInitialEmptyEditorIfNecessary() + maximize = dimensions?.maximized and process.platform isnt 'darwin' @displayWindow({maximize}) @@ -629,6 +631,10 @@ class Atom extends Model @windowEventHandler?.unsubscribe() + openInitialEmptyEditorIfNecessary: -> + if @getLoadSettings().initialPaths?.length is 0 and @workspace.getPaneItems().length is 0 + @workspace.open(null, {isInitialEmptyEditor: true}) + ### Section: Messaging the User ### diff --git a/src/browser/atom-window.coffee b/src/browser/atom-window.coffee index 77888fed4..785c11147 100644 --- a/src/browser/atom-window.coffee +++ b/src/browser/atom-window.coffee @@ -73,7 +73,8 @@ class AtomWindow @browserWindow.loadUrl @getUrl(loadSettings) @browserWindow.focusOnWebView() if @isSpec - @openLocations(locationsToOpen) unless @isSpecWindow() + hasPathToOpen = not (locationsToOpen.length is 1 and not locationsToOpen[0].pathToOpen?) + @openLocations(locationsToOpen) if hasPathToOpen and not @isSpecWindow() getUrl: (loadSettingsObj) -> # Ignore the windowState when passing loadSettings via URL, since it could