mirror of
https://github.com/atom/atom.git
synced 2026-01-26 07:19:06 -05:00
Use buffer marker events to avoid conversions
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user