From eab70d9a9537fd1939792c6b20ddf618b155de50 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Sat, 19 Dec 2015 15:38:34 +0100 Subject: [PATCH] Invalidate spliced block decorations' dimensions --- spec/text-editor-presenter-spec.coffee | 45 ++++++++++++++++++++++++++ src/text-editor-presenter.coffee | 4 ++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index 5a4e8c916..b604a7022 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -2201,6 +2201,51 @@ describe "TextEditorPresenter", -> expect(stateForBlockDecoration(presenter, blockDecoration1)).toBeUndefined() + it "invalidates block decorations that intersect a change in the buffer", -> + blockDecoration1 = addBlockDecorationForScreenRow(9) + blockDecoration2 = addBlockDecorationForScreenRow(10) + blockDecoration3 = addBlockDecorationForScreenRow(11) + presenter = buildPresenter(explicitHeight: 30, lineHeight: 10, tileSize: 2, scrollTop: 0) + + expectValues stateForBlockDecoration(presenter, blockDecoration1), { + decoration: blockDecoration1 + screenRow: 9 + isVisible: false + } + expectValues stateForBlockDecoration(presenter, blockDecoration2), { + decoration: blockDecoration2 + screenRow: 10 + isVisible: false + } + expectValues stateForBlockDecoration(presenter, blockDecoration3), { + decoration: blockDecoration3 + screenRow: 11 + isVisible: false + } + + presenter.setBlockDecorationDimensions(blockDecoration1, 0, 10) + presenter.setBlockDecorationDimensions(blockDecoration2, 0, 10) + presenter.setBlockDecorationDimensions(blockDecoration3, 0, 10) + expect(stateForBlockDecoration(presenter, blockDecoration1)).toBeUndefined() + expect(stateForBlockDecoration(presenter, blockDecoration2)).toBeUndefined() + expect(stateForBlockDecoration(presenter, blockDecoration3)).toBeUndefined() + + editor.setSelectedScreenRange([[10, 0], [12, 0]]) + editor.delete() + presenter.setScrollTop(0) # deleting the buffer causes the editor to autoscroll + + expect(stateForBlockDecoration(presenter, blockDecoration1)).toBeUndefined() + expectValues stateForBlockDecoration(presenter, blockDecoration2), { + decoration: blockDecoration2 + screenRow: 10 + isVisible: false + } + expectValues stateForBlockDecoration(presenter, blockDecoration3), { + decoration: blockDecoration3 + screenRow: 10 + isVisible: false + } + it "invalidates all block decorations when content frame width, window size or bounding client rect change", -> blockDecoration1 = addBlockDecorationForScreenRow(11) presenter = buildPresenter(explicitHeight: 30, lineHeight: 10, tileSize: 2, scrollTop: 0) diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 9a29ec922..73848bdb3 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -1288,8 +1288,10 @@ class TextEditorPresenter newExtent = Point(end - start + screenDelta, 0) invalidatedBlockDecorationIds = @lineTopIndex.splice(Point(start, 0), oldExtent, newExtent) invalidatedBlockDecorationIds.forEach (id) => - newScreenPosition = @model.decorationForId(id).getMarker().getHeadScreenPosition() + decoration = @model.decorationForId(id) + newScreenPosition = decoration.getMarker().getHeadScreenPosition() @lineTopIndex.moveBlock(id, newScreenPosition) + @invalidatedDimensionsByBlockDecoration.add(decoration) didAddBlockDecoration: (decoration) -> return if not decoration.isType('block') or @observedBlockDecorations.has(decoration)