mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Include block decorations as a separate object on presenter's state
This commit is contained in:
parent
8a54a2c15b
commit
526a97562e
@ -2064,6 +2064,72 @@ describe "TextEditorPresenter", ->
|
||||
flashCount: 2
|
||||
}
|
||||
|
||||
describe ".blockDecorations", ->
|
||||
stateForBlockDecoration = (presenter, decoration) ->
|
||||
presenter.getState().content.blockDecorations[decoration.id]
|
||||
|
||||
it "contains state for block decorations, indicating the screen row they belong to both initially and when their markers move", ->
|
||||
item = {}
|
||||
blockDecoration1 = editor.addBlockDecorationForScreenRow(0, item)
|
||||
blockDecoration2 = editor.addBlockDecorationForScreenRow(4, item)
|
||||
blockDecoration3 = editor.addBlockDecorationForScreenRow(4, item)
|
||||
blockDecoration4 = editor.addBlockDecorationForScreenRow(10, item)
|
||||
presenter = buildPresenter(explicitHeight: 30, scrollTop: 0)
|
||||
|
||||
expectValues stateForBlockDecoration(presenter, blockDecoration1), {
|
||||
decoration: blockDecoration1
|
||||
screenRow: 0
|
||||
}
|
||||
expectValues stateForBlockDecoration(presenter, blockDecoration2), {
|
||||
decoration: blockDecoration2
|
||||
screenRow: 4
|
||||
}
|
||||
expectValues stateForBlockDecoration(presenter, blockDecoration3), {
|
||||
decoration: blockDecoration3
|
||||
screenRow: 4
|
||||
}
|
||||
expectValues stateForBlockDecoration(presenter, blockDecoration4), {
|
||||
decoration: blockDecoration4
|
||||
screenRow: 10
|
||||
}
|
||||
|
||||
waitsForStateToUpdate presenter, ->
|
||||
editor.getBuffer().insert([0, 0], 'Hello world \n\n\n\n')
|
||||
|
||||
runs ->
|
||||
expectValues stateForBlockDecoration(presenter, blockDecoration1), {
|
||||
decoration: blockDecoration1
|
||||
screenRow: 4
|
||||
}
|
||||
expectValues stateForBlockDecoration(presenter, blockDecoration2), {
|
||||
decoration: blockDecoration2
|
||||
screenRow: 8
|
||||
}
|
||||
expectValues stateForBlockDecoration(presenter, blockDecoration3), {
|
||||
decoration: blockDecoration3
|
||||
screenRow: 8
|
||||
}
|
||||
expectValues stateForBlockDecoration(presenter, blockDecoration4), {
|
||||
decoration: blockDecoration4
|
||||
screenRow: 14
|
||||
}
|
||||
|
||||
waitsForStateToUpdate presenter, ->
|
||||
blockDecoration2.destroy()
|
||||
blockDecoration4.destroy()
|
||||
|
||||
runs ->
|
||||
expectValues stateForBlockDecoration(presenter, blockDecoration1), {
|
||||
decoration: blockDecoration1
|
||||
screenRow: 4
|
||||
}
|
||||
expect(stateForBlockDecoration(presenter, blockDecoration2)).toBeUndefined()
|
||||
expectValues stateForBlockDecoration(presenter, blockDecoration3), {
|
||||
decoration: blockDecoration3
|
||||
screenRow: 8
|
||||
}
|
||||
expect(stateForBlockDecoration(presenter, blockDecoration4)).toBeUndefined()
|
||||
|
||||
describe ".overlays", ->
|
||||
[item] = []
|
||||
stateForOverlay = (presenter, decoration) ->
|
||||
|
@ -90,7 +90,7 @@ class BlockDecorationsPresenter {
|
||||
}
|
||||
|
||||
addDecorationToScreenRow (screenRow, decoration) {
|
||||
let decorations = this.getDecorationsByScreenRow(screenRow)
|
||||
let decorations = this.decorationsForScreenRow(screenRow)
|
||||
if (!decorations.has(decoration)) {
|
||||
decorations.add(decoration)
|
||||
this.screenRowByDecoration.set(decoration, screenRow)
|
||||
@ -103,14 +103,14 @@ class BlockDecorationsPresenter {
|
||||
return
|
||||
}
|
||||
|
||||
let decorations = this.getDecorationsByScreenRow(screenRow)
|
||||
let decorations = this.decorationsForScreenRow(screenRow)
|
||||
if (decorations.has(decoration)) {
|
||||
decorations.delete(decoration)
|
||||
this.recalculateScreenRowHeight(screenRow)
|
||||
}
|
||||
}
|
||||
|
||||
getDecorationsByScreenRow (screenRow) {
|
||||
decorationsForScreenRow (screenRow) {
|
||||
if (!this.decorationsByScreenRow.has(screenRow)) {
|
||||
this.decorationsByScreenRow.set(screenRow, new Set())
|
||||
}
|
||||
@ -118,13 +118,17 @@ class BlockDecorationsPresenter {
|
||||
return this.decorationsByScreenRow.get(screenRow)
|
||||
}
|
||||
|
||||
getAllDecorationsByScreenRow () {
|
||||
return this.decorationsByScreenRow
|
||||
}
|
||||
|
||||
getDecorationDimensions (decoration) {
|
||||
return this.dimensionsByDecoration.get(decoration) || {width: 0, height: 0}
|
||||
}
|
||||
|
||||
recalculateScreenRowHeight (screenRow) {
|
||||
let height = 0
|
||||
for (let decoration of this.getDecorationsByScreenRow(screenRow)) {
|
||||
for (let decoration of this.decorationsForScreenRow(screenRow)) {
|
||||
height += this.getDecorationDimensions(decoration).height
|
||||
}
|
||||
this.heightByScreenRow.set(screenRow, height)
|
||||
|
@ -76,6 +76,7 @@ class TextEditorPresenter
|
||||
|
||||
@blockDecorationsPresenter.update()
|
||||
|
||||
@updateBlockDecorationsState()
|
||||
@updateVerticalDimensions()
|
||||
@updateScrollbarDimensions()
|
||||
|
||||
@ -485,7 +486,7 @@ class TextEditorPresenter
|
||||
throw new Error("No line exists for row #{screenRow}. Last screen row: #{@model.getLastScreenRow()}")
|
||||
|
||||
visibleLineIds[line.id] = true
|
||||
blockDecorations = this.blockDecorationsPresenter.getDecorationsByScreenRow(screenRow)
|
||||
blockDecorations = this.blockDecorationsPresenter.decorationsForScreenRow(screenRow)
|
||||
if tileState.lines.hasOwnProperty(line.id)
|
||||
lineState = tileState.lines[line.id]
|
||||
lineState.screenRow = screenRow
|
||||
@ -1205,6 +1206,13 @@ class TextEditorPresenter
|
||||
return unless 0 <= @startRow <= @endRow <= Infinity
|
||||
@decorations = @model.decorationsStateForScreenRowRange(@startRow, @endRow - 1)
|
||||
|
||||
updateBlockDecorationsState: ->
|
||||
@state.content.blockDecorations = {}
|
||||
|
||||
@blockDecorationsPresenter.getAllDecorationsByScreenRow().forEach (decorations, screenRow) =>
|
||||
decorations.forEach (decoration) =>
|
||||
@state.content.blockDecorations[decoration.id] = {decoration, screenRow}
|
||||
|
||||
updateLineDecorations: ->
|
||||
@lineDecorationsByScreenRow = {}
|
||||
@lineNumberDecorationsByScreenRow = {}
|
||||
|
Loading…
Reference in New Issue
Block a user