diff --git a/spec/integration/startup-spec.coffee b/spec/integration/startup-spec.coffee index ae0001814..c2b1b960c 100644 --- a/spec/integration/startup-spec.coffee +++ b/spec/integration/startup-spec.coffee @@ -121,3 +121,24 @@ describe "Starting Atom", -> projectPaths.push(value[0]) .then -> expect(projectPaths.sort()).toEqual([tempDirPath, otherTempDirPath].sort()) + + it "opens the path in the current window if it doesn't have a project path yet", -> + runAtom [], {ATOM_HOME: AtomHome}, (client) -> + client + .waitForExist("atom-workspace") + .startAnotherAtom([tempDirPath], ATOM_HOME: AtomHome) + .waitUntil((-> + @title() + .then(({value}) -> value.indexOf(path.basename(tempDirPath)) >= 0)), 5000) + .waitForWindowCount(1, 5000) + + it "always opens with a single untitled buffer when launched w/ no path", -> + runAtom [], {ATOM_HOME: AtomHome}, (client) -> + client + .waitForExist("atom-workspace") + .waitForPaneItemCount(1, 5000) + + runAtom [], {ATOM_HOME: AtomHome}, (client) -> + client + .waitForExist("atom-workspace") + .waitForPaneItemCount(1, 5000) diff --git a/src/atom.coffee b/src/atom.coffee index 723d235e5..385180dfd 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -96,7 +96,7 @@ class Atom extends Model filename = 'spec' when 'editor' {initialPaths} = @getLoadSettings() - if initialPaths + if initialPaths?.length > 0 sha1 = crypto.createHash('sha1').update(initialPaths.join("\n")).digest('hex') filename = "editor-#{sha1}" diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index a3326690b..32e8ca293 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -360,8 +360,13 @@ class AtomApplication existingWindow = @windowForPaths(pathsToOpen, devMode) # Default to using the specified window or the last focused window + currentWindow = window ? @lastFocusedWindow + if pathsToOpen.every((pathToOpen) -> fs.statSyncNoException(pathToOpen).isFile?()) - existingWindow ?= window ? @lastFocusedWindow + existingWindow ?= currentWindow + + unless currentWindow?.projectPaths?.length > 0 + existingWindow ?= currentWindow if existingWindow? openedWindow = existingWindow diff --git a/src/browser/atom-window.coffee b/src/browser/atom-window.coffee index 19c74d943..77888fed4 100644 --- a/src/browser/atom-window.coffee +++ b/src/browser/atom-window.coffee @@ -18,8 +18,9 @@ class AtomWindow isSpec: null constructor: (settings={}) -> - {@resourcePath, pathToOpen, @locationsToOpen, @isSpec, @exitWhenDone, @safeMode, @devMode} = settings - @locationsToOpen ?= [{pathToOpen}] if pathToOpen + {@resourcePath, pathToOpen, locationsToOpen, @isSpec, @exitWhenDone, @safeMode, @devMode} = settings + locationsToOpen ?= [{pathToOpen}] if pathToOpen + locationsToOpen ?= [] # Normalize to make sure drive letter case is consistent on Windows @resourcePath = path.normalize(@resourcePath) if @resourcePath @@ -52,11 +53,13 @@ class AtomWindow @constructor.includeShellLoadTime = false loadSettings.shellLoadTime ?= Date.now() - global.shellStartTime - loadSettings.initialPaths = for {pathToOpen} in (@locationsToOpen ? []) - if fs.statSyncNoException(pathToOpen).isFile?() - path.dirname(pathToOpen) - else - pathToOpen + loadSettings.initialPaths = + for {pathToOpen} in locationsToOpen when pathToOpen + if fs.statSyncNoException(pathToOpen).isFile?() + path.dirname(pathToOpen) + else + pathToOpen + loadSettings.initialPaths.sort() @projectPaths = loadSettings.initialPaths @@ -70,7 +73,7 @@ class AtomWindow @browserWindow.loadUrl @getUrl(loadSettings) @browserWindow.focusOnWebView() if @isSpec - @openLocations(@locationsToOpen) unless @isSpecWindow() + @openLocations(locationsToOpen) unless @isSpecWindow() getUrl: (loadSettingsObj) -> # Ignore the windowState when passing loadSettings via URL, since it could