mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Restore behavior of reusing focused window for opened files
This commit is contained in:
@@ -2,7 +2,7 @@ path = require "path"
|
||||
temp = require("temp").track()
|
||||
remote = require "remote"
|
||||
async = require "async"
|
||||
{map, extend, once} = require "underscore-plus"
|
||||
{map, extend, once, difference} = require "underscore-plus"
|
||||
{spawn, spawnSync} = require "child_process"
|
||||
webdriverio = require "../../../build/node_modules/webdriverio"
|
||||
|
||||
@@ -67,6 +67,17 @@ buildAtomClient = (args, env) ->
|
||||
expect(result).toBe(true)
|
||||
cb(null)
|
||||
|
||||
.addCommand("waitForNewWindow", (fn, timeout, done) ->
|
||||
@windowHandles()
|
||||
.then(({value}) ->
|
||||
return done() unless isRunning
|
||||
oldWindowHandles = value
|
||||
@call(-> fn.call(this))
|
||||
.waitForWindowCount(oldWindowHandles.length + 1, 5000)
|
||||
.then(({value}) ->
|
||||
[newWindowHandle] = difference(value, oldWindowHandles)
|
||||
@window(newWindowHandle, done))))
|
||||
|
||||
.addCommand "startAnotherWindow", (args, env, done) ->
|
||||
@call ->
|
||||
if isRunning
|
||||
|
||||
@@ -53,39 +53,35 @@ describe "Starting Atom", ->
|
||||
|
||||
# Opening a different directory creates a second window with no
|
||||
# tabs open.
|
||||
.startAnotherWindow([otherTempDirPath], ATOM_HOME: AtomHome)
|
||||
.waitForWindowCount(2, 5000)
|
||||
.then(({value}) -> @window(value[1]))
|
||||
.waitForNewWindow(->
|
||||
@startAnotherWindow([otherTempDirPath], ATOM_HOME: AtomHome)
|
||||
, 5000)
|
||||
.waitForExist("atom-workspace", 5000)
|
||||
.then((exists) -> expect(exists).toBe true)
|
||||
.waitForPaneItemCount(0, 1000)
|
||||
|
||||
it "saves the state of closed windows", ->
|
||||
runAtom [otherTempDirPath], {ATOM_HOME: AtomHome}, (client) ->
|
||||
runAtom [tempDirPath], {ATOM_HOME: AtomHome}, (client) ->
|
||||
client
|
||||
|
||||
# Opening a file in another window creates another window with a tab
|
||||
# open for that file.
|
||||
# In a second window, opening a new buffer creates a new tab.
|
||||
.waitForExist("atom-workspace", 5000)
|
||||
.startAnotherWindow([tempFilePath], ATOM_HOME: AtomHome)
|
||||
.waitForWindowCount(2, 5000)
|
||||
.then(({value}) -> @window(value[1]))
|
||||
.waitForExist("atom-text-editor", 5000)
|
||||
.click("atom-text-editor")
|
||||
.execute(-> atom.workspace.getActiveTextEditor().getText())
|
||||
.then(({value}) -> expect(value).toBe "This file was already here.")
|
||||
.waitForNewWindow(->
|
||||
@startAnotherWindow([otherTempDirPath], ATOM_HOME: AtomHome)
|
||||
, 5000)
|
||||
.waitForPaneItemCount(0, 3000)
|
||||
.execute(-> atom.workspace.open())
|
||||
.waitForPaneItemCount(1, 3000)
|
||||
|
||||
# Closing that window and reopening that directory shows the
|
||||
# previously-opened file.
|
||||
# previously-created new buffer.
|
||||
.execute(-> atom.unloadEditorWindow())
|
||||
.close()
|
||||
.waitForWindowCount(1, 5000)
|
||||
.startAnotherWindow([tempDirPath], ATOM_HOME: AtomHome)
|
||||
.waitForWindowCount(2, 5000)
|
||||
.then(({value}) -> @window(value[1]))
|
||||
.waitForExist("atom-text-editor", 5000)
|
||||
.execute(-> atom.workspace.getActiveTextEditor().getText())
|
||||
.then(({value}) -> expect(value).toBe "This file was already here.")
|
||||
.waitForNewWindow(->
|
||||
@startAnotherWindow([otherTempDirPath], ATOM_HOME: AtomHome)
|
||||
, 5000)
|
||||
.waitForPaneItemCount(1, 5000)
|
||||
|
||||
it "allows multiple project directories to be passed as separate arguments", ->
|
||||
runAtom [tempDirPath, otherTempDirPath], {ATOM_HOME: AtomHome}, (client) ->
|
||||
|
||||
@@ -351,9 +351,13 @@ class AtomApplication
|
||||
pathsToOpen = (fs.normalize(pathToOpen) for pathToOpen in pathsToOpen)
|
||||
locationsToOpen = (@locationForPathToOpen(pathToOpen) for pathToOpen in pathsToOpen)
|
||||
|
||||
unless pidToKillWhenClosed or newWindow # or devMode
|
||||
unless pidToKillWhenClosed or newWindow
|
||||
existingWindow = @windowForPaths(pathsToOpen, devMode)
|
||||
|
||||
# Default to using the specified window or the last focused window
|
||||
if pathsToOpen.every((pathToOpen) -> fs.statSyncNoException(pathToOpen).isFile?())
|
||||
existingWindow ?= window ? @lastFocusedWindow
|
||||
|
||||
if existingWindow?
|
||||
openedWindow = existingWindow
|
||||
openedWindow.openLocations(locationsToOpen)
|
||||
|
||||
Reference in New Issue
Block a user