Move continuous reflow setting into TextEditorElement

This commit is contained in:
Antonio Scandurra
2015-09-17 17:14:00 +02:00
parent 91bb8f518d
commit 3575928cce
5 changed files with 39 additions and 55 deletions

View File

@@ -370,6 +370,25 @@ describe "TextEditorComponent", ->
expect(leafNodes[0].classList.contains('trailing-whitespace')).toBe true
expect(leafNodes[0].classList.contains('leading-whitespace')).toBe false
it "keeps rebuilding lines when continuous reflow is on", ->
wrapperNode.setContinuousReflow(true)
oldLineNodes = componentNode.querySelectorAll(".line")
advanceClock(10)
expect(nextAnimationFrame).toBe(noAnimationFrame)
advanceClock(component.presenter.minimumReflowInterval - 10)
nextAnimationFrame()
newLineNodes = componentNode.querySelectorAll(".line")
expect(oldLineNodes).not.toEqual(newLineNodes)
oldLineNodes = newLineNodes
wrapperNode.setContinuousReflow(false)
advanceClock(component.presenter.minimumReflowInterval)
expect(nextAnimationFrame).toBe(noAnimationFrame)
describe "when showInvisibles is enabled", ->
invisibles = null
@@ -450,33 +469,6 @@ describe "TextEditorComponent", ->
nextAnimationFrame()
expect(component.lineNodeForScreenRow(10).innerHTML).toBe '<span class="indent-guide"><span class="invisible-character">C</span></span><span class="invisible-character">E</span>'
it "keeps rebuilding lines when continuous reflow is on and the editor is focused", ->
atom.config.set("editor.continuousReflow", true)
wrapperNode.focus()
nextAnimationFrame()
oldLineNodes = componentNode.querySelectorAll(".line")
advanceClock(10)
expect(nextAnimationFrame).toBe(noAnimationFrame)
advanceClock(component.presenter.minimumReflowInterval - 10)
nextAnimationFrame()
newLineNodes = componentNode.querySelectorAll(".line")
expect(oldLineNodes).not.toEqual(newLineNodes)
oldLineNodes = newLineNodes
atom.config.set("editor.continuousReflow", false)
wrapperNode.blur()
nextAnimationFrame()
newLineNodes = componentNode.querySelectorAll(".line")
expect(oldLineNodes).toEqual(newLineNodes)
advanceClock(component.presenter.minimumReflowInterval)
expect(nextAnimationFrame).toBe(noAnimationFrame)
describe "when soft wrapping is enabled", ->
beforeEach ->
editor.setText "a line that wraps \n"
@@ -834,10 +826,8 @@ describe "TextEditorComponent", ->
expect(componentNode.querySelector('.gutter').style.display).toBe ''
expect(component.lineNumberNodeForScreenRow(3)?).toBe true
it "keeps rebuilding line numbers when continuous reflow is on and the editor is focused", ->
atom.config.set("editor.continuousReflow", true)
wrapperNode.focus()
nextAnimationFrame()
it "keeps rebuilding line numbers when continuous reflow is on", ->
wrapperNode.setContinuousReflow(true)
oldLineNodes = componentNode.querySelectorAll(".line-number")
@@ -851,13 +841,7 @@ describe "TextEditorComponent", ->
expect(oldLineNodes).not.toEqual(newLineNodes)
oldLineNodes = newLineNodes
atom.config.set("editor.continuousReflow", false)
wrapperNode.blur()
nextAnimationFrame()
newLineNodes = componentNode.querySelectorAll(".line-number")
expect(oldLineNodes).toEqual(newLineNodes)
wrapperNode.setContinuousReflow(false)
advanceClock(component.presenter.minimumReflowInterval)
expect(nextAnimationFrame).toBe(noAnimationFrame)

View File

@@ -217,10 +217,6 @@ module.exports =
type: 'boolean'
default: process.platform isnt 'darwin'
description: 'Increase/decrease the editor font size when pressing the Ctrl key and scrolling the mouse up/down.'
continuousReflow:
type: 'boolean'
default: false
description: 'Track down expensive layouts or style recalculations by continously reflowing the editor. (Has performance overhead)'
if process.platform in ['win32', 'linux']
module.exports.core.properties.autoHideMenuBar =

View File

@@ -819,6 +819,9 @@ class TextEditorComponent
setInputEnabled: (@inputEnabled) -> @inputEnabled
setContinuousReflow: (continuousReflow) ->
@presenter.setContinuousReflow(continuousReflow)
updateParentViewFocusedClassIfNeeded: ->
if @oldState.focused isnt @newState.focused
@hostElement.classList.toggle('is-focused', @newState.focused)

View File

@@ -172,6 +172,12 @@ class TextEditorElement extends HTMLElement
isUpdatedSynchronously: -> @updatedSynchronously
# Extended: Continuously reflows lines and line numbers. (Has performance overhead)
#
# `continousReflow` A {Boolean} indicating whether to keep reflowing or not.
setContinuousReflow: (continuousReflow) ->
@component?.setContinuousReflow(continuousReflow)
# Extended: get the width of a character of text displayed in this element.
#
# Returns a {Number} of pixels.

View File

@@ -172,7 +172,6 @@ class TextEditorPresenter
observeConfig: ->
configParams = {scope: @model.getRootScopeDescriptor()}
@continuousReflow = atom.config.get('editor.continuousReflow', configParams)
@scrollPastEnd = atom.config.get('editor.scrollPastEnd', configParams)
@showLineNumbers = atom.config.get('editor.showLineNumbers', configParams)
@showIndentGuide = atom.config.get('editor.showIndentGuide', configParams)
@@ -203,16 +202,6 @@ class TextEditorPresenter
@emitDidUpdateState()
@configDisposables.add atom.config.onDidChange 'editor.continuousReflow', configParams, ({newValue}) =>
@continuousReflow = newValue
if @continuousReflow
@startReflowing()
else
@stopReflowing()
@emitDidUpdateState()
didChangeGrammar: ->
@observeConfig()
@shouldUpdateContentState = true
@@ -268,9 +257,15 @@ class TextEditorPresenter
@resetTrackedUpdates()
setContinuousReflow: (@continuousReflow) ->
if @continuousReflow
@startReflowing()
else
@stopReflowing()
updateReflowState: ->
@state.content.continuousReflow = @focused and @continuousReflow
@lineNumberGutter.continuousReflow = @focused and @continuousReflow
@state.content.continuousReflow = @continuousReflow
@lineNumberGutter.continuousReflow = @continuousReflow
startReflowing: ->
@reflowingInterval = setInterval(@emitDidUpdateState.bind(this), @minimumReflowInterval)