From c0bed9ab50ebaa704009931cbcbc56c71a2942da Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 24 May 2016 10:49:59 +0200 Subject: [PATCH] :bug: Enforce block decorations to be 'before' by default --- spec/text-editor-presenter-spec.coffee | 15 +++++++++++++++ src/text-editor-presenter.coffee | 8 ++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index c770c74c1..70c5cd0e0 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -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]], diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 14ed2bdc9..5ce25f81a 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -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