diff --git a/src/view/ViewCommandHandlers.js b/src/view/ViewCommandHandlers.js index 59e4d8dccb0..0a114a8e656 100644 --- a/src/view/ViewCommandHandlers.js +++ b/src/view/ViewCommandHandlers.js @@ -49,6 +49,21 @@ define(function (require, exports, module) { var prefs = PreferencesManager.getExtensionPrefs("fonts"); + + /** + * @private + * The currently present font size. Used to detect no-op changes. + * @type {string} + */ + var currFontSize; + + /** + * @private + * The currently present font family. Used to detect no-op changes. + * @type {string} + */ + var currFontFamily; + /** * @const * @type {string} @@ -194,9 +209,7 @@ define(function (require, exports, module) { * @param {string} fontSize The font size with size unit as 'px' or 'em' */ function setFontSize(fontSize) { - var oldValue = prefs.get("fontSize"); - - if (oldValue === fontSize) { + if (currFontSize === fontSize) { return; } @@ -214,7 +227,8 @@ define(function (require, exports, module) { } }); - exports.trigger("fontSizeChange", fontSize, oldValue); + exports.trigger("fontSizeChange", fontSize, currFontSize); + currFontSize = fontSize; prefs.set("fontSize", fontSize); } @@ -232,10 +246,9 @@ define(function (require, exports, module) { * @param {string} fontFamily The font family to be set. It can be a string with multiple comma separated fonts */ function setFontFamily(fontFamily) { - var editor = EditorManager.getCurrentFullEditor(), - oldValue = prefs.get("fontFamily"); + var editor = EditorManager.getCurrentFullEditor(); - if (oldValue === fontFamily) { + if (currFontFamily === fontFamily) { return; } @@ -244,7 +257,8 @@ define(function (require, exports, module) { _addDynamicFontFamily(fontFamily); } - exports.trigger("fontFamilyChange", fontFamily, oldValue); + exports.trigger("fontFamilyChange", fontFamily, currFontFamily); + currFontFamily = fontFamily; prefs.set("fontFamily", fontFamily); if (editor) { @@ -333,8 +347,10 @@ define(function (require, exports, module) { * Initializes the different settings that need to loaded */ function init() { - _addDynamicFontFamily(prefs.get("fontFamily")); - _addDynamicFontSize(prefs.get("fontSize")); + currFontFamily = prefs.get("fontFamily"); + _addDynamicFontFamily(currFontFamily); + currFontSize = prefs.get("fontSize"); + _addDynamicFontSize(currFontSize); _updateUI(); } @@ -488,8 +504,12 @@ define(function (require, exports, module) { PreferencesManager.convertPreferences(module, {"fontSizeAdjustment": "user"}, true, _convertToNewViewState); - prefs.definePreference("fontSize", "string", DEFAULT_FONT_SIZE + "px"); - prefs.definePreference("fontFamily", "string", DEFAULT_FONT_FAMILY); + prefs.definePreference("fontSize", "string", DEFAULT_FONT_SIZE + "px").on("change", function () { + setFontSize(prefs.get("fontSize")); + }); + prefs.definePreference("fontFamily", "string", DEFAULT_FONT_FAMILY).on("change", function () { + setFontFamily(prefs.get("fontFamily")); + }); // Update UI when opening or closing a document MainViewManager.on("currentFileChange", _updateUI);