diff --git a/src/block-decorations-presenter.js b/src/block-decorations-presenter.js index 80f4de6f4..31571f57a 100644 --- a/src/block-decorations-presenter.js +++ b/src/block-decorations-presenter.js @@ -45,22 +45,13 @@ class BlockDecorationsPresenter { update () { if (this.firstUpdate) { - this.fullUpdate() + for (let decoration of this.model.getDecorations({type: "block"})) { + this.observeDecoration(decoration) + } this.firstUpdate = false - } else { - this.incrementalUpdate() } } - fullUpdate () { - for (let decoration of this.model.getDecorations({type: "block"})) { - this.observeDecoration(decoration) - } - } - - incrementalUpdate () { - } - setDimensionsForDecoration (decoration, width, height) { let block = this.blocksByDecoration.get(decoration) if (block) { @@ -74,10 +65,6 @@ class BlockDecorationsPresenter { this.emitter.emit("did-update-state") } - heightForScreenRow (screenRow) { - return this.lineTopIndex.bottomPixelPositionForRow(screenRow) - this.lineTopIndex.topPixelPositionForRow(screenRow) - } - decorationsForScreenRow (screenRow) { let blocks = this.lineTopIndex.allBlocks().filter((block) => block.row == screenRow) return blocks.map((block) => this.decorationsByBlock.get(block.id)).filter((decoration) => decoration) @@ -103,18 +90,21 @@ class BlockDecorationsPresenter { return } - // TODO: change this with a "on manual did change" event. - let didMoveDisposable = decoration.getMarker().onDidChange((markerEvent) => { + let didMoveDisposable = decoration.getMarker().bufferMarker.onDidChange((markerEvent) => { this.didMoveDecoration(decoration, markerEvent) }) let didDestroyDisposable = decoration.onDidDestroy(() => { + this.disposables.remove(didMoveDisposable) + this.disposables.remove(didDestroyDisposable) didMoveDisposable.dispose() didDestroyDisposable.dispose() this.observedDecorations.delete(decoration) this.didDestroyDecoration(decoration) }) + this.disposables.add(didMoveDisposable) + this.disposables.add(didDestroyDisposable) this.didAddDecoration(decoration) this.observedDecorations.add(decoration) } @@ -127,7 +117,12 @@ class BlockDecorationsPresenter { this.emitter.emit("did-update-state") } - didMoveDecoration (decoration, {oldHeadScreenPosition, newHeadScreenPosition}) { + didMoveDecoration (decoration, {textChanged}) { + if (textChanged) { + // No need to move blocks because of a text change, because we already splice on buffer change. + return + } + let block = this.blocksByDecoration.get(decoration) let newScreenRow = decoration.getMarker().getHeadScreenPosition().row this.lineTopIndex.moveBlock(block, newScreenRow) diff --git a/src/linear-line-top-index.js b/src/linear-line-top-index.js index 1c7fa0503..82778933f 100644 --- a/src/linear-line-top-index.js +++ b/src/linear-line-top-index.js @@ -50,6 +50,11 @@ class LineTopIndex { return this.blocks } + blocksHeightForRow (row) { + let blocksForRow = this.blocks.filter((block) => block.row == row) + return blocksForRow.reduce((a, b) => a + b.height, 0) + } + splice (startRow, oldExtent, newExtent) { this.blocks.forEach(function (block) { if (block.row >= startRow) { diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 54ffc041f..72d1cec54 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -715,7 +715,7 @@ class TextEditorPresenter line = @model.tokenizedLineForScreenRow(screenRow) decorationClasses = @lineNumberDecorationClassesForRow(screenRow) foldable = @model.isFoldableAtScreenRow(screenRow) - blockDecorationsHeight = @blockDecorationsPresenter.heightForScreenRow(screenRow) + blockDecorationsHeight = @lineTopIndex.blocksHeightForRow(screenRow) tileState.lineNumbers[line.id] = {screenRow, bufferRow, softWrapped, decorationClasses, foldable, blockDecorationsHeight} visibleLineNumberIds[line.id] = true @@ -725,9 +725,6 @@ class TextEditorPresenter return - getScreenRowHeight: (screenRow) -> - @lineHeight + @blockDecorationsPresenter.heightForScreenRow(screenRow) - updateStartRow: -> return unless @scrollTop? and @lineHeight?