Reset font size if editor.fontSize is changed from anywhere

This commit is contained in:
Machiste Quintana 2015-04-28 22:58:35 -04:00
parent 12b59cf610
commit 2bd7cc9a99
2 changed files with 18 additions and 4 deletions

View File

@ -428,7 +428,7 @@ describe "Workspace", ->
describe "::resetFontSize()", ->
it "resets the font size to the window's starting font size", ->
originalFontSize = 6
originalFontSize = atom.config.get('editor.fontSize')
atom.config.set('editor.fontSize', originalFontSize)
workspace.increaseFontSize()
@ -441,12 +441,22 @@ describe "Workspace", ->
expect(atom.config.get('editor.fontSize')).toBe originalFontSize
it "does nothing if the font size has not been changed", ->
originalFontSize = 6
originalFontSize = atom.config.get('editor.fontSize')
atom.config.set('editor.fontSize', originalFontSize)
workspace.resetFontSize()
expect(atom.config.get('editor.fontSize')).toBe originalFontSize
it "resets the font size when the editor's font size changes", ->
originalFontSize = atom.config.get('editor.fontSize')
atom.config.set('editor.fontSize', originalFontSize + 1)
workspace.resetFontSize()
expect(atom.config.get('editor.fontSize')).toBe originalFontSize
atom.config.set('editor.fontSize', originalFontSize - 1)
workspace.resetFontSize()
expect(atom.config.get('editor.fontSize')).toBe originalFontSize
describe "::openLicense()", ->
it "opens the license as plain-text in a buffer", ->
waitsForPromise -> workspace.openLicense()

View File

@ -75,6 +75,8 @@ class Workspace extends Model
atom.views.addViewProvider Panel, (model) ->
new PanelElement().initialize(model)
@subscribeToFontSize()
# Called by the Serializable mixin during deserialization
deserializeParams: (params) ->
for packageName in params.packagesWithActiveGrammars ? []
@ -612,12 +614,10 @@ class Workspace extends Model
# Increase the editor font size by 1px.
increaseFontSize: ->
@originalFontSize ?= atom.config.get("editor.fontSize")
atom.config.set("editor.fontSize", atom.config.get("editor.fontSize") + 1)
# Decrease the editor font size by 1px.
decreaseFontSize: ->
@originalFontSize ?= atom.config.get("editor.fontSize")
fontSize = atom.config.get("editor.fontSize")
atom.config.set("editor.fontSize", fontSize - 1) if fontSize > 1
@ -626,6 +626,10 @@ class Workspace extends Model
if @originalFontSize
atom.config.set("editor.fontSize", @originalFontSize)
subscribeToFontSize: ->
atom.config.onDidChange 'editor.fontSize', ({newValue, oldValue}) =>
@originalFontSize ?= oldValue
# Removes the item's uri from the list of potential items to reopen.
itemOpened: (item) ->
if typeof item.getURI is 'function'