diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index dac2849c0..0b32ff31f 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -426,6 +426,35 @@ describe "Workspace", -> workspace.decreaseFontSize() expect(atom.config.get('editor.fontSize')).toBe 1 + describe "::resetFontSize()", -> + it "resets the font size to the window's starting font size", -> + originalFontSize = atom.config.get('editor.fontSize') + + workspace.increaseFontSize() + expect(atom.config.get('editor.fontSize')).toBe originalFontSize + 1 + workspace.resetFontSize() + expect(atom.config.get('editor.fontSize')).toBe originalFontSize + workspace.decreaseFontSize() + expect(atom.config.get('editor.fontSize')).toBe originalFontSize - 1 + workspace.resetFontSize() + expect(atom.config.get('editor.fontSize')).toBe originalFontSize + + it "does nothing if the font size has not been changed", -> + originalFontSize = atom.config.get('editor.fontSize') + + 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() diff --git a/src/workspace.coffee b/src/workspace.coffee index 50c4117fb..0e6fb7e40 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -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 ? [] @@ -619,9 +621,14 @@ class Workspace extends Model fontSize = atom.config.get("editor.fontSize") atom.config.set("editor.fontSize", fontSize - 1) if fontSize > 1 - # Restore to a default editor font size. + # Restore to the window's original editor font size. resetFontSize: -> - atom.config.unset("editor.fontSize") + if @originalFontSize + atom.config.set("editor.fontSize", @originalFontSize) + + subscribeToFontSize: -> + atom.config.onDidChange 'editor.fontSize', ({oldValue}) => + @originalFontSize ?= oldValue # Removes the item's uri from the list of potential items to reopen. itemOpened: (item) ->