mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Allow multiple space-delimited classes for highlight decorations
Fixes #5747
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user