Add 'onlyHead' option for decorations

It only decorates the head position of the decoration's marker.
This commit is contained in:
Nathan Sobo
2014-06-25 19:55:55 -06:00
parent 61c7e797b9
commit a2b90cd501
2 changed files with 12 additions and 1 deletions

View File

@@ -324,7 +324,7 @@ describe "EditorComponent", ->
editor.addDecorationForMarker(marker, decoration)
runSetImmediateCallbacks()
it "does not render off-screen lines with line number classes until they are with in the rendered row range", ->
it "does not render off-screen lines with decoration classes until they are with in the rendered row range", ->
node.style.height = 4.5 * lineHeightInPixels + 'px'
component.measureScrollView()
runSetImmediateCallbacks()
@@ -348,6 +348,14 @@ describe "EditorComponent", ->
expect(lineHasClass(3, 'someclass')).toBe true
expect(lineHasClass(4, 'someclass')).toBe false
it "only renders 'onlyHead' decorations on lines containing the marker's head", ->
editor.addDecorationForMarker(marker, type: 'line', class: 'only-head', onlyHead: true)
runSetImmediateCallbacks()
expect(lineHasClass(1, 'only-head')).toBe false
expect(lineHasClass(2, 'only-head')).toBe false
expect(lineHasClass(3, 'only-head')).toBe true
expect(lineHasClass(4, 'only-head')).toBe false
it "removes line classes when a decoration's marker is invalidated", ->
editor.getBuffer().insert([3, 2], 'n')
runSetImmediateCallbacks()

View File

@@ -262,14 +262,17 @@ EditorComponent = React.createClass
for markerId, decorations of decorationsByMarkerId
marker = editor.getMarker(markerId)
screenRange = null
headScreenRow = null
if marker.isValid()
for decoration in decorations
if editor.decorationMatchesType(decoration, 'gutter') or editor.decorationMatchesType(decoration, 'line')
screenRange ?= marker.getScreenRange()
headScreenRow ?= marker.getHeadScreenPosition().row
startRow = screenRange.start.row
endRow = screenRange.end.row
endRow-- if not screenRange.isEmpty() and screenRange.end.column == 0
for screenRow in [startRow..endRow]
continue if decoration.onlyHead and screenRow isnt headScreenRow
decorationsByScreenRow[screenRow] ?= []
decorationsByScreenRow[screenRow].push decoration