From b362f746f8fb21d9850f02ca82cc50e90e126d38 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 27 Feb 2017 15:14:39 -0700 Subject: [PATCH] Fix spurious selections marker layer update to avoid extra render --- spec/text-editor-component-spec.js | 6 ------ src/text-editor.coffee | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index b2a2ba8c3..d8528a460 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -34,12 +34,6 @@ describe('TextEditorComponent', () => { it('renders lines and line numbers for the visible region', async () => { const {component, element, editor} = buildComponent({rowsPerTile: 3}) - // TODO: An extra update is caused by marker layer events being asynchronous, - // so the cursor getting added triggers an update even though we created - // the component after this occurred. We should make marker layer events - // synchronous and batched on the transaction. - await component.getNextUpdatePromise() - expect(element.querySelectorAll('.line-number').length).toBe(13) expect(element.querySelectorAll('.line').length).toBe(13) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index b7e078223..f66159a01 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -210,7 +210,7 @@ class TextEditor extends Model if @cursors.length is 0 and not suppressCursorCreation initialLine = Math.max(parseInt(initialLine) or 0, 0) initialColumn = Math.max(parseInt(initialColumn) or 0, 0) - @addCursorAtBufferPosition([initialLine, initialColumn]) + @addCursorAtBufferPosition([initialLine, initialColumn], {suppressLayerUpdateEvent: true}) @languageMode = new LanguageMode(this) @@ -2140,7 +2140,7 @@ class TextEditor extends Model # # Returns a {Cursor}. addCursorAtBufferPosition: (bufferPosition, options) -> - @selectionsMarkerLayer.markBufferPosition(bufferPosition, {invalidate: 'never'}) + @selectionsMarkerLayer.markBufferPosition(bufferPosition, Object.assign({invalidate: 'never'}, options)) @getLastSelection().cursor.autoscroll() unless options?.autoscroll is false @getLastSelection().cursor