Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #11190 from adobe/marcel/fonts-react-prefs
Browse files Browse the repository at this point in the history
Make font settings react to pref changes
  • Loading branch information
MiguelCastillo committed Jun 1, 2015
2 parents 3323063 + 3c01d66 commit 83b632d
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions src/view/ViewCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}

Expand All @@ -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;
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 83b632d

Please sign in to comment.