Add 'onlyEmpty' and 'onlyNonEmpty' decoration options

This commit is contained in:
Nathan Sobo
2014-06-27 04:56:40 -06:00
parent 70f352251e
commit fa7e388352
2 changed files with 27 additions and 0 deletions

View File

@@ -356,6 +356,28 @@ describe "EditorComponent", ->
expect(lineHasClass(3, 'only-head')).toBe true
expect(lineHasClass(4, 'only-head')).toBe false
it "only renders 'onlyEmpty' decorations on lines for which the marker is empty", ->
editor.addDecorationForMarker(marker, type: 'line', class: 'only-empty', onlyEmpty: true)
runSetImmediateCallbacks()
expect(lineHasClass(2, 'only-empty')).toBe false
expect(lineHasClass(3, 'only-empty')).toBe false
marker.clearTail()
runSetImmediateCallbacks()
expect(lineHasClass(2, 'only-empty')).toBe false
expect(lineHasClass(3, 'only-empty')).toBe true
it "only renders 'onlyNonEmpty' decorations on lines for which the marker is non-empty", ->
editor.addDecorationForMarker(marker, type: 'line', class: 'only-non-empty', onlyNonEmpty: true)
runSetImmediateCallbacks()
expect(lineHasClass(2, 'only-non-empty')).toBe true
expect(lineHasClass(3, 'only-non-empty')).toBe true
marker.clearTail()
runSetImmediateCallbacks()
expect(lineHasClass(2, 'only-non-empty')).toBe false
expect(lineHasClass(3, 'only-non-empty')).toBe false
it "removes line classes when a decoration's marker is invalidated", ->
editor.getBuffer().insert([3, 2], 'n')
runSetImmediateCallbacks()

View File

@@ -273,6 +273,11 @@ EditorComponent = React.createClass
endRow-- if not screenRange.isEmpty() and screenRange.end.column == 0
for screenRow in [startRow..endRow]
continue if decoration.onlyHead and screenRow isnt headScreenRow
if screenRange.isEmpty()
continue if decoration.onlyNonEmpty
else
continue if decoration.onlyEmpty
decorationsByScreenRow[screenRow] ?= []
decorationsByScreenRow[screenRow].push decoration