Honor the updateSynchronously parameter

This commit is contained in:
Antonio Scandurra
2017-04-18 16:32:39 +02:00
parent 15ecbed61f
commit f7c55b9473
3 changed files with 43 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
const {it, fit, ffit, fffit, beforeEach, afterEach, conditionPromise, timeoutPromise} = require('./async-spec-helpers')
const TextEditorComponent = require('../src/text-editor-component')
const TextEditorElement = require('../src/text-editor-element')
const TextEditor = require('../src/text-editor')
const TextBuffer = require('text-buffer')
const fs = require('fs')
@@ -2381,6 +2382,41 @@ describe('TextEditorComponent', () => {
})
})
describe('synchronous updates', () => {
let editorElementWasUpdatedSynchronously
beforeEach(() => {
editorElementWasUpdatedSynchronously = TextEditorElement.prototype.updatedSynchronously
})
afterEach(() => {
TextEditorElement.prototype.setUpdatedSynchronously(editorElementWasUpdatedSynchronously)
})
it('updates synchronously when updatedSynchronously is true', () => {
const editor = buildEditor()
const {element} = new TextEditorComponent({model: editor, updatedSynchronously: true})
jasmine.attachToDOM(element)
editor.setText('Lorem ipsum dolor')
expect(Array.from(element.querySelectorAll('.line:not(.dummy)')).map(l => l.textContent)).toEqual([
editor.lineTextForScreenRow(0)
])
})
it('updates synchronously when creating a component via TextEditor and TextEditorElement.prototype.updatedSynchronously is true', () => {
TextEditorElement.prototype.setUpdatedSynchronously(true)
const editor = buildEditor()
const element = editor.element
jasmine.attachToDOM(element)
editor.setText('Lorem ipsum dolor')
expect(Array.from(element.querySelectorAll('.line:not(.dummy)')).map(l => l.textContent)).toEqual([
editor.lineTextForScreenRow(0)
])
})
})
describe('pixelPositionForScreenPositionSync(point)', () => {
it('returns the pixel position for the given point, regardless of whether or not it is currently on screen', async () => {
const {component, element, editor} = buildComponent({rowsPerTile: 2, autoHeight: false})

View File

@@ -64,6 +64,7 @@ class TextEditorComponent {
this.refs = {}
this.updateSync = this.updateSync.bind(this)
this.updatedSynchronously = this.props.updatedSynchronously
this.didScrollDummyScrollbar = this.didScrollDummyScrollbar.bind(this)
this.didMouseDownOnContent = this.didMouseDownOnContent.bind(this)
this.disposables = new CompositeDisposable()

View File

@@ -13,6 +13,7 @@ Selection = require './selection'
TextMateScopeSelector = require('first-mate').ScopeSelector
GutterContainer = require './gutter-container'
TextEditorComponent = null
TextEditorElement = null
{isDoubleWidthCharacter, isHalfWidthCharacter, isKoreanCharacter, isWrapBoundary} = require './text-utils'
ZERO_WIDTH_NBSP = '\ufeff'
@@ -3581,7 +3582,11 @@ class TextEditor extends Model
@component.element
else
TextEditorComponent ?= require('./text-editor-component')
new TextEditorComponent({model: this, styleManager: atom.styles})
TextEditorElement ?= require('./text-editor-element')
new TextEditorComponent({
model: this,
updatedSynchronously: TextEditorElement.prototype.updatedSynchronously
})
@component.element
# Essential: Retrieves the greyed out placeholder of a mini editor.