Honor the ‘onlyEmpty’ and ‘onlyNonEmpty’ line decoration options

This commit is contained in:
Nathan Sobo
2015-01-21 15:59:59 -07:00
parent 773482467e
commit 62a1210604
2 changed files with 37 additions and 1 deletions

View File

@@ -324,3 +324,31 @@ describe "TextEditorPresenter", ->
expect(lineStateForScreenRow(presenter, 5).decorationClasses).toBeNull()
expect(lineStateForScreenRow(presenter, 6).decorationClasses).toBeNull()
expect(lineStateForScreenRow(presenter, 7).decorationClasses).toBeNull()
it "honors the 'onlyEmpty' option on line decorations", ->
presenter = new TextEditorPresenter(model: editor, clientHeight: 130, scrollTop: 0, lineHeight: 10, lineOverdrawMargin: 0)
marker = editor.markBufferRange([[4, 0], [6, 1]])
decoration = editor.decorateMarker(marker, type: 'line', class: 'a', onlyEmpty: true)
expect(lineStateForScreenRow(presenter, 4).decorationClasses).toBeNull()
expect(lineStateForScreenRow(presenter, 5).decorationClasses).toBeNull()
expect(lineStateForScreenRow(presenter, 6).decorationClasses).toBeNull()
marker.clearTail()
expect(lineStateForScreenRow(presenter, 4).decorationClasses).toBeNull()
expect(lineStateForScreenRow(presenter, 5).decorationClasses).toBeNull()
expect(lineStateForScreenRow(presenter, 6).decorationClasses).toEqual ['a']
it "honors the 'onlyNonEmpty' option on line decorations", ->
presenter = new TextEditorPresenter(model: editor, clientHeight: 130, scrollTop: 0, lineHeight: 10, lineOverdrawMargin: 0)
marker = editor.markBufferRange([[4, 0], [6, 1]])
decoration = editor.decorateMarker(marker, type: 'line', class: 'a', onlyNonEmpty: true)
expect(lineStateForScreenRow(presenter, 4).decorationClasses).toEqual ['a']
expect(lineStateForScreenRow(presenter, 5).decorationClasses).toEqual ['a']
expect(lineStateForScreenRow(presenter, 6).decorationClasses).toEqual ['a']
marker.clearTail()
expect(lineStateForScreenRow(presenter, 6).decorationClasses).toBeNull()

View File

@@ -101,8 +101,16 @@ class TextEditorPresenter
decorationClasses = null
for markerId, decorations of @model.decorationsForScreenRowRange(row, row) when @model.getMarker(markerId).isValid()
for decoration in decorations when decoration.isType('line')
properties = decoration.getProperties()
range = decoration.getMarker().getScreenRange()
if range.isEmpty()
continue if properties.onlyNonEmpty
else
continue if properties.onlyEmpty
decorationClasses ?= []
decorationClasses.push(decoration.getProperties().class)
decorationClasses.push(properties.class)
decorationClasses
setScrollTop: (@scrollTop) ->