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

Commit 3c01d66

Browse files
author
Marcel Gerber
committed
Add proper JSDoc, make sure methods are only called once
1 parent 83dd9d3 commit 3c01d66

1 file changed

Lines changed: 24 additions & 13 deletions

File tree

src/view/ViewCommandHandlers.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,20 @@ define(function (require, exports, module) {
4949

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

52-
// These variables contain the preference values. They are used to no-op in case nothing changed
53-
// and updated *after* the call to setFontSize/setFontFamily.
54-
var fontSizeValue, fontFamilyValue;
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;
5566

5667
/**
5768
* @const
@@ -198,7 +209,7 @@ define(function (require, exports, module) {
198209
* @param {string} fontSize The font size with size unit as 'px' or 'em'
199210
*/
200211
function setFontSize(fontSize) {
201-
if (fontSizeValue === fontSize) {
212+
if (currFontSize === fontSize) {
202213
return;
203214
}
204215

@@ -216,7 +227,8 @@ define(function (require, exports, module) {
216227
}
217228
});
218229

219-
exports.trigger("fontSizeChange", fontSize, fontSizeValue);
230+
exports.trigger("fontSizeChange", fontSize, currFontSize);
231+
currFontSize = fontSize;
220232
prefs.set("fontSize", fontSize);
221233
}
222234

@@ -236,7 +248,7 @@ define(function (require, exports, module) {
236248
function setFontFamily(fontFamily) {
237249
var editor = EditorManager.getCurrentFullEditor();
238250

239-
if (fontFamilyValue === fontFamily) {
251+
if (currFontFamily === fontFamily) {
240252
return;
241253
}
242254

@@ -245,7 +257,8 @@ define(function (require, exports, module) {
245257
_addDynamicFontFamily(fontFamily);
246258
}
247259

248-
exports.trigger("fontFamilyChange", fontFamily, fontFamilyValue);
260+
exports.trigger("fontFamilyChange", fontFamily, currFontFamily);
261+
currFontFamily = fontFamily;
249262
prefs.set("fontFamily", fontFamily);
250263

251264
if (editor) {
@@ -334,10 +347,10 @@ define(function (require, exports, module) {
334347
* Initializes the different settings that need to loaded
335348
*/
336349
function init() {
337-
fontFamilyValue = prefs.get("fontFamily");
338-
_addDynamicFontFamily(fontFamilyValue);
339-
fontSizeValue = prefs.get("fontSize");
340-
_addDynamicFontSize(fontSizeValue);
350+
currFontFamily = prefs.get("fontFamily");
351+
_addDynamicFontFamily(currFontFamily);
352+
currFontSize = prefs.get("fontSize");
353+
_addDynamicFontSize(currFontSize);
341354
_updateUI();
342355
}
343356

@@ -493,11 +506,9 @@ define(function (require, exports, module) {
493506

494507
prefs.definePreference("fontSize", "string", DEFAULT_FONT_SIZE + "px").on("change", function () {
495508
setFontSize(prefs.get("fontSize"));
496-
fontSizeValue = prefs.get("fontSize");
497509
});
498510
prefs.definePreference("fontFamily", "string", DEFAULT_FONT_FAMILY).on("change", function () {
499511
setFontFamily(prefs.get("fontFamily"));
500-
fontFamilyValue = prefs.get("fontFamily");
501512
});
502513

503514
// Update UI when opening or closing a document

0 commit comments

Comments
 (0)