Merge pull request #11829 from atom/as-block-decorations-default-position-before

Enforce block decorations to be 'before' by default
This commit is contained in:
Antonio Scandurra
2016-05-24 13:41:27 +02:00
2 changed files with 22 additions and 7 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')
@@ -1582,15 +1589,15 @@ describe "TextEditorPresenter", ->
expect(stateForCursor(presenter, 4)).toEqual {top: 8 * 10, left: 4 * 10, width: 10, height: 10}
blockDecoration1 = addBlockDecorationBeforeScreenRow(0)
blockDecoration2 = addBlockDecorationBeforeScreenRow(1)
blockDecoration2 = addBlockDecorationAfterScreenRow(1)
waitsForStateToUpdate presenter, ->
presenter.setBlockDecorationDimensions(blockDecoration1, 0, 30)
presenter.setBlockDecorationDimensions(blockDecoration2, 0, 10)
runs ->
expect(stateForCursor(presenter, 0)).toEqual {top: 50, left: 2 * 10, width: 10, height: 10}
expect(stateForCursor(presenter, 1)).toEqual {top: 60, left: 4 * 10, width: 10, height: 10}
expect(stateForCursor(presenter, 0)).toEqual {top: 1 * 10 + 30, left: 2 * 10, width: 10, height: 10}
expect(stateForCursor(presenter, 1)).toEqual {top: 2 * 10 + 30 + 10, left: 4 * 10, width: 10, height: 10}
expect(stateForCursor(presenter, 2)).toBeUndefined()
expect(stateForCursor(presenter, 3)).toBeUndefined()
expect(stateForCursor(presenter, 4)).toBeUndefined()
@@ -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