Use buffer marker events to avoid conversions

This commit is contained in:
Antonio Scandurra
2015-12-02 19:11:51 +01:00
parent 9ef3ecf378
commit fcb8a13f4a
3 changed files with 20 additions and 23 deletions

View File

@@ -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)

View File

@@ -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) {

View File

@@ -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?