Register style elements change events in AtomEnvironment.initialize

...and fix spec/workspace-element-spec.js
This commit is contained in:
Antonio Scandurra
2017-04-13 15:10:56 +02:00
parent 1d01d499a9
commit f3c48c8b70
2 changed files with 12 additions and 8 deletions

View File

@@ -230,28 +230,32 @@ describe('WorkspaceElement', () => {
editorElement = editor.getElement()
})
it("updates the font-size based on the 'editor.fontSize' config value", () => {
it("updates the font-size based on the 'editor.fontSize' config value", async () => {
const initialCharWidth = editor.getDefaultCharWidth()
expect(getComputedStyle(editorElement).fontSize).toBe(atom.config.get('editor.fontSize') + 'px')
atom.config.set('editor.fontSize', atom.config.get('editor.fontSize') + 5)
await editorElement.component.getNextUpdatePromise()
expect(getComputedStyle(editorElement).fontSize).toBe(atom.config.get('editor.fontSize') + 'px')
expect(editor.getDefaultCharWidth()).toBeGreaterThan(initialCharWidth)
})
it("updates the font-family based on the 'editor.fontFamily' config value", () => {
it("updates the font-family based on the 'editor.fontFamily' config value", async () => {
const initialCharWidth = editor.getDefaultCharWidth()
let fontFamily = atom.config.get('editor.fontFamily')
expect(getComputedStyle(editorElement).fontFamily).toBe(fontFamily)
atom.config.set('editor.fontFamily', 'sans-serif')
fontFamily = atom.config.get('editor.fontFamily')
await editorElement.component.getNextUpdatePromise()
expect(getComputedStyle(editorElement).fontFamily).toBe(fontFamily)
expect(editor.getDefaultCharWidth()).not.toBe(initialCharWidth)
})
it("updates the line-height based on the 'editor.lineHeight' config value", () => {
it("updates the line-height based on the 'editor.lineHeight' config value", async () => {
const initialLineHeight = editor.getLineHeightInPixels()
atom.config.set('editor.lineHeight', '30px')
await editorElement.component.getNextUpdatePromise()
expect(getComputedStyle(editorElement).lineHeight).toBe(atom.config.get('editor.lineHeight'))
expect(editor.getLineHeightInPixels()).not.toBe(initialLineHeight)
})

View File

@@ -250,6 +250,11 @@ class AtomEnvironment extends Model
@attachSaveStateListeners()
@windowEventHandler.initialize(@window, @document)
didChangeStyles = @didChangeStyles.bind(this)
@disposables.add(@styles.onDidAddStyleElement(didChangeStyles))
@disposables.add(@styles.onDidUpdateStyleElement(didChangeStyles))
@disposables.add(@styles.onDidRemoveStyleElement(didChangeStyles))
@observeAutoHideMenuBar()
@history.initialize(@window.localStorage)
@@ -697,11 +702,6 @@ class AtomEnvironment extends Model
callback = => @applicationDelegate.didSaveWindowState()
@saveState({isUnloading: true}).catch(callback).then(callback)
didChangeStyles = @didChangeStyles.bind(this)
@disposables.add(@styles.onDidAddStyleElement(didChangeStyles))
@disposables.add(@styles.onDidUpdateStyleElement(didChangeStyles))
@disposables.add(@styles.onDidRemoveStyleElement(didChangeStyles))
@listenForUpdates()
@registerDefaultTargetForKeymaps()