mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 23:48:05 +03:00
Update all text editor styles in one batch
This allows DOM mutation observers to detect changes to the global styles.
This commit is contained in:
parent
3715e05bed
commit
ba58631984
@ -12,7 +12,6 @@ class WorkspaceElement extends HTMLElement
|
|||||||
|
|
||||||
createdCallback: ->
|
createdCallback: ->
|
||||||
@subscriptions = new CompositeDisposable
|
@subscriptions = new CompositeDisposable
|
||||||
@initializeGlobalTextEditorStyleSheet()
|
|
||||||
@initializeContent()
|
@initializeContent()
|
||||||
@observeScrollbarStyle()
|
@observeScrollbarStyle()
|
||||||
@observeTextEditorFontConfig()
|
@observeTextEditorFontConfig()
|
||||||
@ -26,10 +25,6 @@ class WorkspaceElement extends HTMLElement
|
|||||||
@subscriptions.dispose()
|
@subscriptions.dispose()
|
||||||
@model.destroy()
|
@model.destroy()
|
||||||
|
|
||||||
initializeGlobalTextEditorStyleSheet: ->
|
|
||||||
atom.styles.addStyleSheet('atom-text-editor {}', sourcePath: 'global-text-editor-styles')
|
|
||||||
@globalTextEditorStyleSheet = document.head.querySelector('style[source-path="global-text-editor-styles"]').sheet
|
|
||||||
|
|
||||||
initializeContent: ->
|
initializeContent: ->
|
||||||
@classList.add 'workspace'
|
@classList.add 'workspace'
|
||||||
@setAttribute 'tabindex', -1
|
@setAttribute 'tabindex', -1
|
||||||
@ -54,9 +49,20 @@ class WorkspaceElement extends HTMLElement
|
|||||||
@classList.add("scrollbars-visible-when-scrolling")
|
@classList.add("scrollbars-visible-when-scrolling")
|
||||||
|
|
||||||
observeTextEditorFontConfig: ->
|
observeTextEditorFontConfig: ->
|
||||||
@subscriptions.add atom.config.observe 'editor.fontSize', @setTextEditorFontSize.bind(this)
|
@updateGlobalTextEditorStyleSheet()
|
||||||
@subscriptions.add atom.config.observe 'editor.fontFamily', @setTextEditorFontFamily.bind(this)
|
@subscriptions.add atom.config.onDidChange 'editor.fontSize', @updateGlobalTextEditorStyleSheet.bind(this)
|
||||||
@subscriptions.add atom.config.observe 'editor.lineHeight', @setTextEditorLineHeight.bind(this)
|
@subscriptions.add atom.config.onDidChange 'editor.fontFamily', @updateGlobalTextEditorStyleSheet.bind(this)
|
||||||
|
@subscriptions.add atom.config.onDidChange 'editor.lineHeight', @updateGlobalTextEditorStyleSheet.bind(this)
|
||||||
|
|
||||||
|
updateGlobalTextEditorStyleSheet: ->
|
||||||
|
styleSheetSource = """
|
||||||
|
atom-text-editor {
|
||||||
|
font-size: #{atom.config.get('editor.fontSize')}px;
|
||||||
|
font-family: #{atom.config.get('editor.fontFamily')};
|
||||||
|
line-height: #{atom.config.get('editor.lineHeight')};
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
atom.styles.addStyleSheet(styleSheetSource, sourcePath: 'global-text-editor-styles')
|
||||||
|
|
||||||
createSpacePenShim: ->
|
createSpacePenShim: ->
|
||||||
WorkspaceView ?= require './workspace-view'
|
WorkspaceView ?= require './workspace-view'
|
||||||
@ -87,20 +93,6 @@ class WorkspaceElement extends HTMLElement
|
|||||||
|
|
||||||
getModel: -> @model
|
getModel: -> @model
|
||||||
|
|
||||||
setTextEditorFontSize: (fontSize) ->
|
|
||||||
@updateGlobalEditorStyle('font-size', fontSize + 'px')
|
|
||||||
|
|
||||||
setTextEditorFontFamily: (fontFamily) ->
|
|
||||||
@updateGlobalEditorStyle('font-family', fontFamily)
|
|
||||||
|
|
||||||
setTextEditorLineHeight: (lineHeight) ->
|
|
||||||
@updateGlobalEditorStyle('line-height', lineHeight)
|
|
||||||
|
|
||||||
updateGlobalEditorStyle: (property, value) ->
|
|
||||||
editorRule = @globalTextEditorStyleSheet.cssRules[0]
|
|
||||||
editorRule.style[property] = value
|
|
||||||
atom.themes.emitter.emit 'did-update-stylesheet', @globalTextEditorStyleSheet
|
|
||||||
|
|
||||||
handleFocus: (event) ->
|
handleFocus: (event) ->
|
||||||
@model.getActivePane().activate()
|
@model.getActivePane().activate()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user