🐛 Enforce block decorations to be 'before' by default

This commit is contained in:
Antonio Scandurra
2016-05-24 10:49:59 +02:00
parent 8710096cfe
commit c0bed9ab50
2 changed files with 19 additions and 4 deletions

View File

@@ -1370,6 +1370,13 @@ describe "TextEditorPresenter", ->
expect(lineStateForScreenRow(presenter, 12).precedingBlockDecorations).toEqual([])
expect(lineStateForScreenRow(presenter, 12).followingBlockDecorations).toEqual([])
it "inserts block decorations before the line if not specified otherwise", ->
blockDecoration = editor.decorateMarker(editor.markScreenPosition([4, 0]), {type: "block"})
presenter = buildPresenter()
expect(lineStateForScreenRow(presenter, 4).precedingBlockDecorations).toEqual [blockDecoration]
expect(lineStateForScreenRow(presenter, 4).followingBlockDecorations).toEqual []
describe ".decorationClasses", ->
it "adds decoration classes to the relevant line state objects, both initially and when decorations change", ->
marker1 = editor.addMarkerLayer(maintainHistory: true).markBufferRange([[4, 0], [6, 2]], invalidate: 'touch')
@@ -1604,6 +1611,14 @@ describe "TextEditorPresenter", ->
runs ->
expect(stateForCursor(presenter, 0)).toEqual {top: 0, left: 0, width: 10, height: 10}
it "considers block decorations to be before a line by default", ->
editor.setCursorScreenPosition([4, 0])
blockDecoration = editor.decorateMarker(editor.markScreenPosition([4, 0]), {type: "block"})
presenter = buildPresenter()
presenter.setBlockDecorationDimensions(blockDecoration, 0, 6)
expect(stateForCursor(presenter, 0)).toEqual {top: 4 * 10 + 6, left: 0, width: 10, height: 10}
it "updates when ::scrollTop changes", ->
editor.setSelectedBufferRanges([
[[1, 2], [1, 2]],

View File

@@ -1083,12 +1083,12 @@ class TextEditorPresenter
return if @blockDecorationsToRenderById[decoration.getId()]
screenRow = decoration.getMarker().getHeadScreenPosition().row
if decoration.getProperties().position is "before"
@precedingBlockDecorationsByScreenRow[screenRow] ?= []
@precedingBlockDecorationsByScreenRow[screenRow].push(decoration)
else
if decoration.getProperties().position is "after"
@followingBlockDecorationsByScreenRow[screenRow] ?= []
@followingBlockDecorationsByScreenRow[screenRow].push(decoration)
else
@precedingBlockDecorationsByScreenRow[screenRow] ?= []
@precedingBlockDecorationsByScreenRow[screenRow].push(decoration)
@state.content.blockDecorations[decoration.getId()] = {decoration, screenRow, isVisible}
@blockDecorationsToRenderById[decoration.getId()] = true