diff --git a/src/styles-element.coffee b/src/styles-element.coffee index 60d0ab92e..47f859153 100644 --- a/src/styles-element.coffee +++ b/src/styles-element.coffee @@ -59,6 +59,10 @@ class StylesElement extends HTMLElement break @insertBefore(styleElementClone, insertBefore) + + if @context is 'atom-text-editor' + @upgradeDeprecatedSelectors(styleElementClone, styleElement.sourcePath) + @emitter.emit 'did-add-style-element', styleElementClone styleElementRemoved: (styleElement) -> @@ -78,4 +82,28 @@ class StylesElement extends HTMLElement styleElementMatchesContext: (styleElement) -> not @context? or styleElement.context is @context + upgradeDeprecatedSelectors: (styleElement, sourcePath) -> + upgradedSelectors = [] + + for rule in styleElement.sheet.cssRules + continue if /\:host/.test(rule.selectorText) + + inputSelector = rule.selectorText + outputSelector = rule.selectorText + .replace(/\.editor-colors($|[ >])/g, ':host$1') + .replace(/\.editor(\.[^ ,>]+)/g, ':host($1)') + .replace(/\.editor($|[ ,>])/g, ':host$1') + + unless inputSelector is outputSelector + rule.selectorText = outputSelector + upgradedSelectors.push({inputSelector, outputSelector}) + + if upgradedSelectors.length > 0 + warning = "Upgraded the following syntax theme selectors in `#{sourcePath}` for shadow DOM compatibility:\n\n" + for {inputSelector, outputSelector} in upgradedSelectors + warning += "`#{inputSelector}` => `#{outputSelector}`\n" + + warning += "\nSee the upgrade guide for information on removing this warning." + console.warn(warning) + module.exports = StylesElement = document.registerElement 'atom-styles', prototype: StylesElement.prototype