Allow multiple space-delimited classes for highlight decorations

Fixes #5747
This commit is contained in:
Nathan Sobo
2015-02-25 14:35:24 -07:00
parent fb89f04c5d
commit 986e8bf85f
2 changed files with 20 additions and 2 deletions

View File

@@ -1171,6 +1171,14 @@ describe "TextEditorComponent", ->
regions = componentNode.querySelectorAll('.test-highlight .region')
expect(regions.length).toBe 2
it "allows multiple space-delimited decoration classes", ->
decoration.setProperties(type: 'highlight', class: 'foo bar')
nextAnimationFrame()
expect(componentNode.querySelectorAll('.foo.bar').length).toBe 1
decoration.setProperties(type: 'highlight', class: 'bar baz')
nextAnimationFrame()
expect(componentNode.querySelectorAll('.bar.baz').length).toBe 1
it "renders classes on the regions directly if 'deprecatedRegionClass' option is defined", ->
decoration = editor.decorateMarker(marker, type: 'highlight', class: 'test-highlight', deprecatedRegionClass: 'test-highlight-region')
nextAnimationFrame()

View File

@@ -1,4 +1,5 @@
RegionStyleProperties = ['top', 'left', 'right', 'width', 'height']
SpaceRegex = /\s+/
module.exports =
class HighlightsComponent
@@ -44,8 +45,17 @@ class HighlightsComponent
# update class
if newHighlightState.class isnt oldHighlightState.class
highlightNode.classList.remove(oldHighlightState.class) if oldHighlightState.class?
highlightNode.classList.add(newHighlightState.class)
if oldHighlightState.class?
if SpaceRegex.test(oldHighlightState.class)
highlightNode.classList.remove(oldHighlightState.class.split(SpaceRegex)...)
else
highlightNode.classList.remove(oldHighlightState.class)
if SpaceRegex.test(newHighlightState.class)
highlightNode.classList.add(newHighlightState.class.split(SpaceRegex)...)
else
highlightNode.classList.add(newHighlightState.class)
oldHighlightState.class = newHighlightState.class
@updateHighlightRegions(id, newHighlightState)