diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index ad3b7dd20..1f4689752 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -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}) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index dd4d2f640..b40a02bae 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -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() diff --git a/src/text-editor.coffee b/src/text-editor.coffee index ac0a05ca5..1b374404a 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -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.