From a1ba470c5b476145ca0f68240eb8678e353f607c Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 24 Feb 2015 12:09:10 -0800 Subject: [PATCH] Don't add project paths when opening a file in an existing window --- spec/integration/startup-spec.coffee | 28 +++++++++++++++++----------- src/window-event-handler.coffee | 11 +++++++++-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/spec/integration/startup-spec.coffee b/spec/integration/startup-spec.coffee index 5a0cef6fb..f3253b81e 100644 --- a/spec/integration/startup-spec.coffee +++ b/spec/integration/startup-spec.coffee @@ -11,15 +11,13 @@ fs.writeFileSync(path.join(AtomHome, 'config.cson'), fs.readFileSync(path.join(_ runAtom = require("./helpers/start-atom") describe "Starting Atom", -> - [tempDirPath, tempFilePath, otherTempDirPath] = [] + [tempDirPath, otherTempDirPath] = [] beforeEach -> jasmine.useRealClock() tempDirPath = temp.mkdirSync("empty-dir") otherTempDirPath = temp.mkdirSync("another-temp-dir") - tempFilePath = path.join(tempDirPath, "an-existing-file") - fs.writeFileSync(tempFilePath, "This file was already here.") describe "opening a new file", -> it "opens the parent directory and creates an empty text editor", -> @@ -39,14 +37,19 @@ describe "Starting Atom", -> .execute -> atom.workspace.getActiveTextEditor().getText() .then ({value}) -> expect(value).toBe "Hello!" - describe "opening a directory that is already open in an existing window", -> - it "reuses that existing window", -> + describe "when there is already a window open", -> + it "reuses that window when opening files, but not when opening directories", -> + tempFilePath = path.join(temp.mkdirSync("a-third-dir"), "a-file") + fs.writeFileSync(tempFilePath, "This file was already here.") + runAtom [path.join(tempDirPath, "new-file")], {ATOM_HOME: AtomHome}, (client) -> client .waitForWindowCount(1, 1000) .waitForExist("atom-workspace", 5000) .waitForPaneItemCount(1, 5000) + # Opening another file reuses the same window and does not change the + # project paths. .startAnotherAtom([tempFilePath], ATOM_HOME: AtomHome) .waitForPaneItemCount(2, 5000) .waitForWindowCount(1, 1000) @@ -55,6 +58,7 @@ describe "Starting Atom", -> .execute -> atom.workspace.getActiveTextEditor().getText() .then ({value: text}) -> expect(text).toBe "This file was already here." + # Opening another directory creates a second window. .waitForNewWindow(-> @startAnotherAtom([otherTempDirPath], ATOM_HOME: AtomHome) , 5000) @@ -65,7 +69,7 @@ describe "Starting Atom", -> describe "reopening a directory that was previously opened", -> it "remembers the state of the window", -> - runAtom [otherTempDirPath], {ATOM_HOME: AtomHome}, (client) -> + runAtom [tempDirPath], {ATOM_HOME: AtomHome}, (client) -> client .waitForExist("atom-workspace", 5000) .waitForPaneItemCount(0, 3000) @@ -73,24 +77,26 @@ describe "Starting Atom", -> .waitForPaneItemCount(1, 3000) .execute -> atom.unloadEditorWindow() - runAtom [otherTempDirPath], {ATOM_HOME: AtomHome}, (client) -> + runAtom [tempDirPath], {ATOM_HOME: AtomHome}, (client) -> client .waitForExist("atom-workspace", 5000) .waitForPaneItemCount(1, 5000) describe "opening multiple directories simultaneously", -> it "shows them all in the tree-view", -> + nestedDir = path.join(otherTempDirPath, "nested-dir") + fs.mkdirSync(nestedDir) + runAtom [tempDirPath, otherTempDirPath, "--multi-folder"], {ATOM_HOME: AtomHome}, (client) -> client .waitForExist("atom-workspace", 5000) .treeViewRootDirectories() .then ({value}) -> expect(value).toEqual([tempDirPath, otherTempDirPath]) - # Opening a file in one of the directories reuses the same window - # and does not change the project paths. - .startAnotherAtom([tempFilePath], ATOM_HOME: AtomHome) + # Opening one of those directories again reuses the same window and + # does not change the project paths. + .startAnotherAtom([nestedDir], ATOM_HOME: AtomHome) .waitForExist("atom-workspace", 5000) - .waitForPaneItemCount(1, 5000) .treeViewRootDirectories() .then ({value}) -> expect(value).toEqual([tempDirPath, otherTempDirPath]) diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index 6d68f3437..1384f0c4a 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -18,9 +18,16 @@ class WindowEventHandler @subscribe ipc, 'message', (message, detail) -> switch message when 'open-locations' + needsProjectPaths = atom.project?.getPaths().length is 0 + for {pathToOpen, initialLine, initialColumn} in detail - if pathToOpen and (fs.existsSync(pathToOpen) or fs.existsSync(path.dirname(pathToOpen))) - atom.project?.addPath(pathToOpen) + if pathToOpen? and needsProjectPaths + if fs.existsSync(pathToOpen) + atom.project.addPath(pathToOpen) + else + dirToOpen = path.dirname(pathToOpen) + if fs.existsSync(dirToOpen) + atom.project.addPath(dirToOpen) unless fs.isDirectorySync(pathToOpen) atom.workspace?.open(pathToOpen, {initialLine, initialColumn})