Remove more usages of getView, document getElement API

This commit is contained in:
Max Brunsfeld
2017-04-05 17:02:59 -07:00
parent 78d8e67609
commit 9ecbc85be5
4 changed files with 12 additions and 58 deletions

View File

@@ -14,7 +14,7 @@ describe('WorkspaceElement', () => {
it('transfers focus to the active pane', () => {
const workspaceElement = atom.workspace.getElement()
jasmine.attachToDOM(workspaceElement)
const activePaneElement = atom.views.getView(atom.workspace.getActivePane())
const activePaneElement = atom.workspace.getActivePane().getElement()
document.body.focus()
expect(document.activeElement).not.toBe(activePaneElement)
workspaceElement.focus()

View File

@@ -290,7 +290,7 @@ class AtomEnvironment extends Model
@workspace.openTextFile(@getUserInitScriptPath())
registerDefaultTargetForKeymaps: ->
@keymaps.defaultTarget = @views.getView(@workspace)
@keymaps.defaultTarget = @workspace.getElement()
observeAutoHideMenuBar: ->
@disposables.add @config.onDidChange 'core.autoHideMenuBar', ({newValue}) =>
@@ -655,8 +655,7 @@ class AtomEnvironment extends Model
storeWindowBackground: ->
return if @inSpecMode()
workspaceElement = @views.getView(@workspace)
backgroundColor = @window.getComputedStyle(workspaceElement)['background-color']
backgroundColor = @window.getComputedStyle(@workspace.getElement())['background-color']
@window.localStorage.setItem('atom:window-background-color', backgroundColor)
# Call this method when establishing a real application window.
@@ -700,7 +699,7 @@ class AtomEnvironment extends Model
if process.platform is 'darwin' and @config.get('core.titleBar') is 'hidden'
@document.body.classList.add('hidden-title-bar')
@document.body.appendChild(@views.getView(@workspace))
@document.body.appendChild(@workspace.getElement())
@backgroundStylesheet?.remove()
@watchProjectPaths()
@@ -1018,8 +1017,8 @@ class AtomEnvironment extends Model
dispatchApplicationMenuCommand: (command, arg) ->
activeElement = @document.activeElement
# Use the workspace element if body has focus
if activeElement is @document.body and workspaceElement = @views.getView(@workspace)
activeElement = workspaceElement
if activeElement is @document.body
activeElement = @workspace.getElement()
@commands.dispatch(activeElement, command, arg)
dispatchContextMenuCommand: (command, args...) ->

View File

@@ -63,7 +63,7 @@ class PaneContainerElement extends HTMLElement
y = pointB.y - pointA.y
Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))
paneView = @views.getView(@model.getActivePane())
paneView = @model.getActivePane().getElement()
box = @boundingBoxForPaneView(paneView)
paneViews = _.toArray(@querySelectorAll('atom-pane'))

View File

@@ -23,28 +23,6 @@ AnyConstructor = Symbol('any-constructor')
# an ideal tool for implementing views in Atom.
#
# You can access the `ViewRegistry` object via `atom.views`.
#
# ## Examples
#
# ### Getting the workspace element
#
# ```coffee
# workspaceElement = atom.views.getView(atom.workspace)
# ```
#
# ### Getting An Editor Element
#
# ```coffee
# textEditor = atom.workspace.getActiveTextEditor()
# textEditorElement = atom.views.getView(textEditor)
# ```
#
# ### Getting A Pane Element
#
# ```coffee
# pane = atom.workspace.getActivePane()
# paneElement = pane.getElement()
# ```
module.exports =
class ViewRegistry
animationFrameRequest: null
@@ -120,42 +98,19 @@ class ViewRegistry
# layer, but view layer access may be necessary if you want to perform DOM
# manipulation that isn't supported via the model API.
#
# ## Examples
#
# ### Getting An Editor Element
#
# ```coffee
# textEditor = atom.workspace.getActiveTextEditor()
# textEditorElement = atom.views.getView(textEditor)
# ```
#
# ### Getting A Pane Element
#
# ```coffee
# pane = atom.workspace.getActivePane()
# paneElement = pane.getElement()
# ```
#
# ### Getting The Workspace Element
#
# ```coffee
# workspaceElement = atom.views.getView(atom.workspace)
# ```
#
# * `object` The object for which you want to retrieve a view. This can be a
# pane item, a pane, or the workspace itself.
#
# ## View Resolution Algorithm
#
# The view associated with the object is resolved using the following
# sequence
#
# 1. Is the object an instance of `HTMLElement`? If true, return the object.
# 2. Does the object have a property named `element` with a value which is
# 2. Does the object have a method named `getElement` that returns an
# instance of `HTMLElement`? If true, return that value.
# 3. Does the object have a property named `element` with a value which is
# an instance of `HTMLElement`? If true, return the property value.
# 3. Is the object a jQuery object, indicated by the presence of a `jquery`
# 4. Is the object a jQuery object, indicated by the presence of a `jquery`
# property? If true, return the root DOM element (i.e. `object[0]`).
# 4. Has a view provider been registered for the object? If true, use the
# 5. Has a view provider been registered for the object? If true, use the
# provider to create a view associated with the object, and return the
# view.
#