From cc9ed043c72be3dab5c3cad5d1c607f9486407ae Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 24 Feb 2015 12:39:27 +0100 Subject: [PATCH] :racehorse: Update needed cursors only --- src/text-editor-presenter.coffee | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index b76666209..955b63cc4 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -259,16 +259,22 @@ class TextEditorPresenter updateCursorsState: -> @state.content.cursors = {} - return unless @startRow? and @endRow? and @hasPixelRectRequirements() and @baseCharacterWidth? - - for cursor in @model.cursors # using property directly to avoid allocation - if cursor.isVisible() and @startRow <= cursor.getScreenRow() < @endRow - pixelRect = @pixelRectForScreenRange(cursor.getScreenRange()) - pixelRect.width = @baseCharacterWidth if pixelRect.width is 0 - @state.content.cursors[cursor.id] = pixelRect + @updateCursorState(cursor) for cursor in @model.cursors # using property directly to avoid allocation @emitter.emit 'did-update-state' + + updateCursorState: (cursor, destroyOnly = false) -> + delete @state.content.cursors[cursor.id] + + return if destroyOnly + return unless @startRow? and @endRow? and @hasPixelRectRequirements() and @baseCharacterWidth? + return unless cursor.isVisible() and @startRow <= cursor.getScreenRow() < @endRow + + pixelRect = @pixelRectForScreenRange(cursor.getScreenRange()) + pixelRect.width = @baseCharacterWidth if pixelRect.width is 0 + @state.content.cursors[cursor.id] = pixelRect + updateOverlaysState: -> return unless @hasPixelRectRequirements() @@ -948,16 +954,17 @@ class TextEditorPresenter didChangePositionDisposable = cursor.onDidChangePosition => @updateHiddenInputState() if cursor.isLastCursor() @pauseCursorBlinking() - @updateCursorsState() + @updateCursorState(cursor) - didChangeVisibilityDisposable = cursor.onDidChangeVisibility(@updateCursorsState.bind(this)) + didChangeVisibilityDisposable = cursor.onDidChangeVisibility => + @updateCursorState(cursor) didDestroyDisposable = cursor.onDidDestroy => @disposables.remove(didChangePositionDisposable) @disposables.remove(didChangeVisibilityDisposable) @disposables.remove(didDestroyDisposable) @updateHiddenInputState() - @updateCursorsState() + @updateCursorState(cursor, true) @disposables.add(didChangePositionDisposable) @disposables.add(didChangeVisibilityDisposable) @@ -967,7 +974,7 @@ class TextEditorPresenter @observeCursor(cursor) @updateHiddenInputState() @pauseCursorBlinking() - @updateCursorsState() + @updateCursorState(cursor) startBlinkingCursors: -> @toggleCursorBlinkHandle = setInterval(@toggleCursorBlink.bind(this), @getCursorBlinkPeriod() / 2)