Eliminate polling of overlay decoration dimensions

And remove pollDOM method entirely.

Signed-off-by: Max Brunsfeld <maxbrunsfeld@github.com>
This commit is contained in:
Nathan Sobo
2017-02-08 18:11:21 -07:00
committed by Thomas Johansen
parent 549bce5637
commit bbbb629f70
2 changed files with 10 additions and 12 deletions

View File

@@ -1,3 +1,5 @@
elementResizeDetector = require('element-resize-detector')({strategy: 'scroll'})
module.exports =
class OverlayManager
constructor: (@presenter, @container, @views) ->
@@ -12,6 +14,7 @@ class OverlayManager
unless state.content.overlays.hasOwnProperty(id)
delete @overlaysById[id]
overlayNode.remove()
elementResizeDetector.uninstall(overlayNode)
shouldUpdateOverlay: (decorationId, overlay) ->
cachedOverlay = @overlaysById[decorationId]
@@ -19,10 +22,6 @@ class OverlayManager
cachedOverlay.pixelPosition?.top isnt overlay.pixelPosition?.top or
cachedOverlay.pixelPosition?.left isnt overlay.pixelPosition?.left
measureOverlays: ->
for decorationId, {itemView} of @overlaysById
@measureOverlay(decorationId, itemView)
measureOverlay: (decorationId, itemView) ->
contentMargin = parseInt(getComputedStyle(itemView)['margin-left']) ? 0
@presenter.setOverlayDimensions(decorationId, itemView.offsetWidth, itemView.offsetHeight, contentMargin)
@@ -33,13 +32,19 @@ class OverlayManager
unless overlayNode = cachedOverlay?.overlayNode
overlayNode = document.createElement('atom-overlay')
overlayNode.classList.add(klass) if klass?
elementResizeDetector.listenTo(overlayNode, =>
if overlayNode.parentElement?
@measureOverlay(decorationId, itemView)
)
@container.appendChild(overlayNode)
@overlaysById[decorationId] = cachedOverlay = {overlayNode, itemView}
# The same node may be used in more than one overlay. This steals the node
# back if it has been displayed in another overlay.
overlayNode.appendChild(itemView) if overlayNode.childNodes.length is 0
overlayNode.appendChild(itemView) unless overlayNode.contains(itemView)
cachedOverlay.pixelPosition = pixelPosition
overlayNode.style.top = pixelPosition.top + 'px'
overlayNode.style.left = pixelPosition.left + 'px'
@measureOverlay(decorationId, itemView)

View File

@@ -106,8 +106,6 @@ class TextEditorComponent
@disposables.add @themes.onDidChangeActiveThemes @onAllThemesLoaded
@disposables.add scrollbarStyle.onDidChangePreferredScrollbarStyle @refreshScrollbars
@disposables.add @views.pollDocument(@pollDOM)
@updateSync()
@initialized = true
@@ -204,7 +202,6 @@ class TextEditorComponent
@linesComponent.updateSync(@presenter.getPreMeasurementState())
readAfterUpdateSync: =>
@overlayManager?.measureOverlays()
@linesComponent.measureBlockDecorations()
@offScreenBlockDecorationsComponent.measureBlockDecorations()
@@ -753,10 +750,6 @@ class TextEditorComponent
@domNode? and (@domNode.offsetHeight > 0 or @domNode.offsetWidth > 0)
pollDOM: =>
if @isVisible()
@overlayManager?.measureOverlays()
# Measure explicitly-styled height and width and relay them to the model. If
# these values aren't explicitly styled, we assume the editor is unconstrained
# and use the scrollHeight / scrollWidth as its height and width in