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

Commit 83b632d

Browse files
Merge pull request #11190 from adobe/marcel/fonts-react-prefs
Make font settings react to pref changes
2 parents 3323063 + 3c01d66 commit 83b632d

1 file changed

Lines changed: 32 additions & 12 deletions

File tree

src/view/ViewCommandHandlers.js

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ define(function (require, exports, module) {
4949

5050
var prefs = PreferencesManager.getExtensionPrefs("fonts");
5151

52+
53+
/**
54+
* @private
55+
* The currently present font size. Used to detect no-op changes.
56+
* @type {string}
57+
*/
58+
var currFontSize;
59+
60+
/**
61+
* @private
62+
* The currently present font family. Used to detect no-op changes.
63+
* @type {string}
64+
*/
65+
var currFontFamily;
66+
5267
/**
5368
* @const
5469
* @type {string}
@@ -194,9 +209,7 @@ define(function (require, exports, module) {
194209
* @param {string} fontSize The font size with size unit as 'px' or 'em'
195210
*/
196211
function setFontSize(fontSize) {
197-
var oldValue = prefs.get("fontSize");
198-
199-
if (oldValue === fontSize) {
212+
if (currFontSize === fontSize) {
200213
return;
201214
}
202215

@@ -214,7 +227,8 @@ define(function (require, exports, module) {
214227
}
215228
});
216229

217-
exports.trigger("fontSizeChange", fontSize, oldValue);
230+
exports.trigger("fontSizeChange", fontSize, currFontSize);
231+
currFontSize = fontSize;
218232
prefs.set("fontSize", fontSize);
219233
}
220234

@@ -232,10 +246,9 @@ define(function (require, exports, module) {
232246
* @param {string} fontFamily The font family to be set. It can be a string with multiple comma separated fonts
233247
*/
234248
function setFontFamily(fontFamily) {
235-
var editor = EditorManager.getCurrentFullEditor(),
236-
oldValue = prefs.get("fontFamily");
249+
var editor = EditorManager.getCurrentFullEditor();
237250

238-
if (oldValue === fontFamily) {
251+
if (currFontFamily === fontFamily) {
239252
return;
240253
}
241254

@@ -244,7 +257,8 @@ define(function (require, exports, module) {
244257
_addDynamicFontFamily(fontFamily);
245258
}
246259

247-
exports.trigger("fontFamilyChange", fontFamily, oldValue);
260+
exports.trigger("fontFamilyChange", fontFamily, currFontFamily);
261+
currFontFamily = fontFamily;
248262
prefs.set("fontFamily", fontFamily);
249263

250264
if (editor) {
@@ -333,8 +347,10 @@ define(function (require, exports, module) {
333347
* Initializes the different settings that need to loaded
334348
*/
335349
function init() {
336-
_addDynamicFontFamily(prefs.get("fontFamily"));
337-
_addDynamicFontSize(prefs.get("fontSize"));
350+
currFontFamily = prefs.get("fontFamily");
351+
_addDynamicFontFamily(currFontFamily);
352+
currFontSize = prefs.get("fontSize");
353+
_addDynamicFontSize(currFontSize);
338354
_updateUI();
339355
}
340356

@@ -488,8 +504,12 @@ define(function (require, exports, module) {
488504

489505
PreferencesManager.convertPreferences(module, {"fontSizeAdjustment": "user"}, true, _convertToNewViewState);
490506

491-
prefs.definePreference("fontSize", "string", DEFAULT_FONT_SIZE + "px");
492-
prefs.definePreference("fontFamily", "string", DEFAULT_FONT_FAMILY);
507+
prefs.definePreference("fontSize", "string", DEFAULT_FONT_SIZE + "px").on("change", function () {
508+
setFontSize(prefs.get("fontSize"));
509+
});
510+
prefs.definePreference("fontFamily", "string", DEFAULT_FONT_FAMILY).on("change", function () {
511+
setFontFamily(prefs.get("fontFamily"));
512+
});
493513

494514
// Update UI when opening or closing a document
495515
MainViewManager.on("currentFileChange", _updateUI);

0 commit comments

Comments
 (0)