mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
When opening a file, don't also create an edit session or an empty buffer
Also: RootView.proto.activeEditor no longer constructs an editor. To open an empty buffer, call RootView.proto.open with no path argument. It will build a new editor if needed.
This commit is contained in:
@@ -24,6 +24,7 @@ describe "RootView", ->
|
||||
expect(rootView.editors().length).toBe 1
|
||||
expect(rootView.editors()[0]).toHaveClass 'active'
|
||||
expect(rootView.activeEditor().buffer.getPath()).toBe path
|
||||
expect(rootView.activeEditor().editSessions.length).toBe 1
|
||||
expect(document.title).toBe path
|
||||
|
||||
describe "when pathToOpen references a directory", ->
|
||||
@@ -116,7 +117,7 @@ describe "RootView", ->
|
||||
rootView.attachToDom()
|
||||
expect(rootView).toMatchSelector(':focus')
|
||||
|
||||
rootView.activeEditor() # lazily create an editor
|
||||
rootView.open() # create an editor
|
||||
expect(rootView).not.toMatchSelector(':focus')
|
||||
expect(rootView.activeEditor().isFocused).toBeTruthy()
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class RootView extends View
|
||||
@on 'show-console', => window.showConsole()
|
||||
@one 'attach', => @focus()
|
||||
@on 'focus', (e) =>
|
||||
if @editors().length
|
||||
if @activeEditor()
|
||||
@activeEditor().focus()
|
||||
false
|
||||
else
|
||||
@@ -42,7 +42,7 @@ class RootView extends View
|
||||
@project = new Project(fs.directory(pathToOpen))
|
||||
@open(pathToOpen) if fs.isFile(pathToOpen)
|
||||
else if not panesViewState?
|
||||
@activeEditor().setBuffer(new Buffer)
|
||||
@open()
|
||||
|
||||
@deserializePanes(panesViewState) if panesViewState
|
||||
|
||||
@@ -65,7 +65,15 @@ class RootView extends View
|
||||
when 'Editor' then Editor.deserialize(viewState)
|
||||
|
||||
open: (path) ->
|
||||
@activeEditor().setBuffer(@project.open(path))
|
||||
buffer = if path then @project.open(path) else new Buffer
|
||||
|
||||
if @activeEditor()
|
||||
@activeEditor().setBuffer(buffer)
|
||||
else
|
||||
editor = new Editor({ buffer })
|
||||
pane = new Pane(editor)
|
||||
@panes.append(pane)
|
||||
editor.focus()
|
||||
|
||||
editorFocused: (editor) ->
|
||||
if @panes.containsElement(editor)
|
||||
@@ -89,19 +97,10 @@ class RootView extends View
|
||||
@panes.find('.editor').map -> $(this).view()
|
||||
|
||||
activeEditor: ->
|
||||
editor = @panes.find('.editor.active')
|
||||
if editor.length
|
||||
if (editor = @panes.find('.editor.active')).length
|
||||
editor.view()
|
||||
else
|
||||
editor = @panes.find('.editor:first')
|
||||
if editor.length
|
||||
editor.view()
|
||||
else
|
||||
editor = new Editor
|
||||
pane = new Pane(editor)
|
||||
@panes.append(pane)
|
||||
editor.focus()
|
||||
editor
|
||||
@panes.find('.editor:first').view()
|
||||
|
||||
adjustPaneDimensions: ->
|
||||
rootPane = @panes.children().first().view()
|
||||
|
||||
Reference in New Issue
Block a user