From ea391d017de83394d45d853c1a2d739332cc75ac Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 19 Aug 2015 11:32:16 +0200 Subject: [PATCH 1/2] :racehorse: Batch cursor updates --- src/text-editor-presenter.coffee | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 825600a70..b79abc267 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -410,10 +410,7 @@ class TextEditorPresenter @updateCursorState(cursor) for cursor in @model.cursors # using property directly to avoid allocation return - updateCursorState: (cursor, destroyOnly = false) -> - delete @state.content.cursors[cursor.id] - - return if destroyOnly + updateCursorState: (cursor) -> return unless @startRow? and @endRow? and @hasPixelRectRequirements() and @baseCharacterWidth? return unless cursor.isVisible() and @startRow <= cursor.getScreenRow() < @endRow @@ -1365,20 +1362,20 @@ class TextEditorPresenter observeCursor: (cursor) -> didChangePositionDisposable = cursor.onDidChangePosition => @shouldUpdateHiddenInputState = true if cursor.isLastCursor() + @shouldUpdateCursorsState = true @pauseCursorBlinking() - @updateCursorState(cursor) @emitDidUpdateState() didChangeVisibilityDisposable = cursor.onDidChangeVisibility => - @updateCursorState(cursor) + @shouldUpdateCursorsState = true didDestroyDisposable = cursor.onDidDestroy => @disposables.remove(didChangePositionDisposable) @disposables.remove(didChangeVisibilityDisposable) @disposables.remove(didDestroyDisposable) @shouldUpdateHiddenInputState = true - @updateCursorState(cursor, true) + @shouldUpdateCursorsState = true @emitDidUpdateState() @@ -1389,8 +1386,9 @@ class TextEditorPresenter didAddCursor: (cursor) -> @observeCursor(cursor) @shouldUpdateHiddenInputState = true + @shouldUpdateCursorsState = true @pauseCursorBlinking() - @updateCursorState(cursor) + @emitDidUpdateState() startBlinkingCursors: -> From 5c519036dcfc65aa3b6dac435733a74d870904b6 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 20 Aug 2015 10:04:31 +0200 Subject: [PATCH 2/2] :fire: Avoid emitting event on cursor update --- src/text-editor-presenter.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index b79abc267..5c7bac851 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -418,8 +418,6 @@ class TextEditorPresenter pixelRect.width = @baseCharacterWidth if pixelRect.width is 0 @state.content.cursors[cursor.id] = pixelRect - @emitDidUpdateState() - updateOverlaysState: -> return unless @hasOverlayPositionRequirements() @@ -1370,6 +1368,8 @@ class TextEditorPresenter didChangeVisibilityDisposable = cursor.onDidChangeVisibility => @shouldUpdateCursorsState = true + @emitDidUpdateState() + didDestroyDisposable = cursor.onDidDestroy => @disposables.remove(didChangePositionDisposable) @disposables.remove(didChangeVisibilityDisposable)