From f4b228c9087a8fdc2a9ce6f9c13e74c50069afae Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Mon, 27 Apr 2015 18:25:01 -0400 Subject: [PATCH 1/5] Reset font size to window's starting font size --- spec/workspace-spec.coffee | 13 +++++++++++++ src/workspace.coffee | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index dac2849c0..7d8ea03b3 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -425,6 +425,19 @@ describe "Workspace", -> expect(atom.config.get('editor.fontSize')).toBe 1 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 = 6 + + atom.config.set('editor.fontSize', originalFontSize) + 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 describe "::openLicense()", -> it "opens the license as plain-text in a buffer", -> diff --git a/src/workspace.coffee b/src/workspace.coffee index 50c4117fb..7d460add0 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -612,16 +612,18 @@ 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 - # Restore to a default editor font size. + # Restore to the window's original editor font size. resetFontSize: -> - atom.config.unset("editor.fontSize") + atom.config.set("editor.fontSize", @originalFontSize) # Removes the item's uri from the list of potential items to reopen. itemOpened: (item) -> From 12b59cf610e08aefa22872ef76eaa8fce3ccb6d0 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Tue, 28 Apr 2015 05:49:22 -0400 Subject: [PATCH 2/5] Only reset font size if font size has been changed --- spec/workspace-spec.coffee | 8 ++++++++ src/workspace.coffee | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index 7d8ea03b3..61da334bb 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -425,6 +425,7 @@ describe "Workspace", -> expect(atom.config.get('editor.fontSize')).toBe 1 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 = 6 @@ -439,6 +440,13 @@ describe "Workspace", -> workspace.resetFontSize() expect(atom.config.get('editor.fontSize')).toBe originalFontSize + it "does nothing if the font size has not been changed", -> + originalFontSize = 6 + + atom.config.set('editor.fontSize', originalFontSize) + 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 7d460add0..2f70e4316 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -623,7 +623,8 @@ class Workspace extends Model # Restore to the window's original editor font size. resetFontSize: -> - atom.config.set("editor.fontSize", @originalFontSize) + if @originalFontSize + atom.config.set("editor.fontSize", @originalFontSize) # Removes the item's uri from the list of potential items to reopen. itemOpened: (item) -> From 2bd7cc9a99895c8392d3a6e4909cc95724b890a1 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Tue, 28 Apr 2015 22:58:35 -0400 Subject: [PATCH 3/5] Reset font size if editor.fontSize is changed from anywhere --- spec/workspace-spec.coffee | 14 ++++++++++++-- src/workspace.coffee | 8 ++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index 61da334bb..9b8ce4d50 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -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() diff --git a/src/workspace.coffee b/src/workspace.coffee index 2f70e4316..07040463b 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 ? [] @@ -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' From a76205256d2cbee2a51c221001d0d8489d1fde95 Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Tue, 28 Apr 2015 23:09:31 -0400 Subject: [PATCH 4/5] Only need oldValue --- src/workspace.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/workspace.coffee b/src/workspace.coffee index 07040463b..0e6fb7e40 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -627,7 +627,7 @@ class Workspace extends Model atom.config.set("editor.fontSize", @originalFontSize) subscribeToFontSize: -> - atom.config.onDidChange 'editor.fontSize', ({newValue, oldValue}) => + atom.config.onDidChange 'editor.fontSize', ({oldValue}) => @originalFontSize ?= oldValue # Removes the item's uri from the list of potential items to reopen. From 4fb58317ec69cd5eda65e0a88315c0ccc088382c Mon Sep 17 00:00:00 2001 From: Machiste Quintana Date: Thu, 30 Apr 2015 13:41:47 -0400 Subject: [PATCH 5/5] :fire: Redundant lines --- spec/workspace-spec.coffee | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index 9b8ce4d50..0b32ff31f 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -430,7 +430,6 @@ describe "Workspace", -> it "resets the font size to the window's starting font size", -> originalFontSize = atom.config.get('editor.fontSize') - atom.config.set('editor.fontSize', originalFontSize) workspace.increaseFontSize() expect(atom.config.get('editor.fontSize')).toBe originalFontSize + 1 workspace.resetFontSize() @@ -443,7 +442,6 @@ describe "Workspace", -> it "does nothing if the font size has not been changed", -> originalFontSize = atom.config.get('editor.fontSize') - atom.config.set('editor.fontSize', originalFontSize) workspace.resetFontSize() expect(atom.config.get('editor.fontSize')).toBe originalFontSize