Exclude EditorViews that are mini editors from WorkspaceView::eachEditorView

Fixes #1900
This commit is contained in:
Corey Johnson
2014-04-24 09:24:39 -07:00
parent ad8bd98c9a
commit 2ceccf5239
2 changed files with 14 additions and 3 deletions

View File

@@ -2,6 +2,7 @@
Q = require 'q'
path = require 'path'
temp = require 'temp'
EditorView = require '../src/editor-view'
PaneView = require '../src/pane-view'
Workspace = require '../src/workspace'
@@ -222,6 +223,14 @@ describe "WorkspaceView", ->
expect(count).toBe 1
expect(callbackEditor).toBe atom.workspaceView.getActiveView()
it "does not invoke the callback for mini editors", ->
editorViewCreatedHandler = jasmine.createSpy('editorViewCreatedHandler')
atom.workspaceView.eachEditorView(editorViewCreatedHandler)
editorViewCreatedHandler.reset()
miniEditor = new EditorView(mini: true)
atom.workspaceView.append(miniEditor)
expect(editorViewCreatedHandler).not.toHaveBeenCalled()
it "returns a subscription that can be disabled", ->
count = 0
callback = (editor) -> count++

View File

@@ -320,15 +320,17 @@ class WorkspaceView extends View
@panes.getPaneViews()
# Public: Register a function to be called for every current and future
# editor view in the workspace.
# editor view in the workspace (only includes {EditorView}s that are pane
# items).
#
# callback - A {Function} with an {EditorView} as its only argument.
#
# Returns a subscription object with an `.off` method that you can call to
# unregister the callback.
eachEditorView: (callback) ->
callback(editor) for editor in @getEditorViews()
attachedCallback = (e, editor) -> callback(editor)
callback(editorView) for editorView in @getEditorViews()
attachedCallback = (e, editorView) ->
callback(editorView) unless editorView.mini
@on('editor:attached', attachedCallback)
off: => @off('editor:attached', attachedCallback)