Skip to content

Commit

Permalink
Preserve specificity when transforming atom-text-editor::shadow
Browse files Browse the repository at this point in the history
Simply replace ::shadow with .editor to preserve the specificity of the
transformed rule. This isn't beautiful, but it's the only way to
guarantee that the styling transition is smooth enough to justify not
bumping the major.
  • Loading branch information
Nathan Sobo committed Nov 1, 2016
1 parent daf7904 commit 4ccd700
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 8 additions & 7 deletions spec/style-manager-spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const temp = require('temp')
const StyleManager = require('../src/style-manager')

describe('StyleManager', () => {
let [styleManager, addEvents, removeEvents, updateEvents] = []

beforeEach(() => {
styleManager = new StyleManager({configDirPath: atom.getConfigDirPath()})
styleManager = new StyleManager({configDirPath: temp.mkdirSync('atom-config')})
addEvents = []
removeEvents = []
updateEvents = []
Expand Down Expand Up @@ -43,12 +44,12 @@ describe('StyleManager', () => {
atom-text-editor[mini].is-focused::shadow .class-7 { color: green; }
`)
expect(Array.from(styleManager.getStyleElements()[0].sheet.cssRules).map((r) => r.selectorText)).toEqual([
'atom-text-editor .class-1, atom-text-editor .class-2',
'atom-text-editor > .class-3',
'atom-text-editor.editor .class-1, atom-text-editor.editor .class-2',
'atom-text-editor.editor > .class-3',
'atom-text-editor .class-4',
'another-element::shadow .class-5',
'atom-text-editor[data-grammar*=\"js\"] .class-6',
'atom-text-editor[mini].is-focused .class-7'
'atom-text-editor[data-grammar*=\"js\"].editor .class-6',
'atom-text-editor[mini].is-focused.editor .class-7'
])
})

Expand All @@ -75,8 +76,8 @@ describe('StyleManager', () => {
`)
expect(Array.from(styleManager.getStyleElements()[1].sheet.cssRules).map((r) => r.selectorText)).toEqual([
'.source > .js, .source.coffee',
'atom-text-editor .syntax--source > .syntax--js',
'atom-text-editor[mini].is-focused .syntax--source > .syntax--js',
'atom-text-editor.editor .syntax--source > .syntax--js',
'atom-text-editor[mini].is-focused.editor .syntax--source > .syntax--js',
'atom-text-editor .source > .js'
])
})
Expand Down
3 changes: 2 additions & 1 deletion src/style-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ function transformDeprecatedShadowDOMSelectors (css, context) {
}
} else {
if (previousNodeIsAtomTextEditor && node.type === 'pseudo' && node.value === '::shadow') {
selector.removeChild(node)
node.type = 'className'
node.value = '.editor'
targetsAtomTextEditorShadow = true
}
}
Expand Down

0 comments on commit 4ccd700

Please sign in to comment.