Store useShadowDOM setting when TextEditorElement is created

Rather than reading it repeatedly, since the value could potentially
change over time.
This commit is contained in:
Nathan Sobo
2014-11-12 14:40:09 -07:00
committed by Ben Ogle
parent 263ff21cc1
commit 08971562cd
3 changed files with 10 additions and 5 deletions

View File

@@ -59,7 +59,7 @@ LinesComponent = React.createClass
@renderedDecorationsByLineId = {}
componentDidMount: ->
if atom.config.get('editor.useShadowDOM')
if @props.useShadowDOM
insertionPoint = document.createElement('content')
insertionPoint.setAttribute('select', '.overlayer')
@getDOMNode().appendChild(insertionPoint)

View File

@@ -50,7 +50,7 @@ TextEditorComponent = React.createClass
render: ->
{focused, showIndentGuide, showLineNumbers, visible} = @state
{editor, mini, cursorBlinkPeriod, cursorBlinkResumeDelay, hostElement} = @props
{editor, mini, cursorBlinkPeriod, cursorBlinkResumeDelay, hostElement, useShadowDOM} = @props
maxLineNumberDigits = editor.getLineCount().toString().length
hasSelection = editor.getLastSelection()? and !editor.getLastSelection().isEmpty()
style = {}
@@ -117,7 +117,7 @@ TextEditorComponent = React.createClass
@scrollingVertically, scrollHeight, scrollWidth, mouseWheelScreenRow,
visible, scrollViewHeight, @scopedCharacterWidthsChangeCount, lineWidth, @useHardwareAcceleration,
placeholderText, @performedInitialMeasurement, @backgroundColor, cursorPixelRects,
cursorBlinkPeriod, cursorBlinkResumeDelay, mini
cursorBlinkPeriod, cursorBlinkResumeDelay, mini, useShadowDOM
}
ScrollbarComponent

View File

@@ -28,6 +28,8 @@ class TextEditorElement extends HTMLElement
@setAttribute('tabindex', -1)
if atom.config.get('editor.useShadowDOM')
@useShadowDOM = true
unless ShadowStyleSheet?
ShadowStyleSheet = document.createElement('style')
ShadowStyleSheet.textContent = atom.themes.loadLessStylesheet(require.resolve('../static/text-editor-shadow.less'))
@@ -45,6 +47,8 @@ class TextEditorElement extends HTMLElement
@shadowRoot.appendChild(@stylesElement)
@shadowRoot.appendChild(@rootElement)
else
@useShadowDOM = false
@stylesElement = document.head.querySelector('atom-styles')
@rootElement = this
@@ -95,10 +99,11 @@ class TextEditorElement extends HTMLElement
editor: @model
mini: @model.mini
lineOverdrawMargin: @lineOverdrawMargin
useShadowDOM: @useShadowDOM
)
@component = React.renderComponent(@componentDescriptor, @rootElement)
unless atom.config.get('editor.useShadowDOM')
unless @useShadowDOM
inputNode = @component.refs.input.getDOMNode()
inputNode.addEventListener 'focus', @focused.bind(this)
inputNode.addEventListener 'blur', => @dispatchEvent(new FocusEvent('blur', bubbles: false))
@@ -116,7 +121,7 @@ class TextEditorElement extends HTMLElement
@focusOnAttach = true
blurred: (event) ->
unless atom.config.get('editor.useShadowDOM')
unless @useShadowDOM
if event.relatedTarget is @component?.refs.input?.getDOMNode()
event.stopImmediatePropagation()
return