From 79ccbe90aa37edd427aee21cdbf58488bcf40d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Wed, 12 Mar 2014 23:23:48 -0300 Subject: [PATCH 1/7] Set the font size before openning the documents --- src/brackets.js | 3 +- src/view/ViewCommandHandlers.js | 79 ++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/brackets.js b/src/brackets.js index c644d820b79..fee3f749bdd 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -99,6 +99,7 @@ define(function (require, exports, module) { ColorUtils = require("utils/ColorUtils"), CodeInspection = require("language/CodeInspection"), NativeApp = require("utils/NativeApp"), + ViewCommandHandlers = require("view/ViewCommandHandlers"), _ = require("thirdparty/lodash"); // Load modules that self-register and just need to get included in the main project @@ -107,7 +108,6 @@ define(function (require, exports, module) { require("editor/EditorStatusBar"); require("editor/EditorCommandHandlers"); require("editor/EditorOptionHandlers"); - require("view/ViewCommandHandlers"); require("help/HelpCommandHandlers"); require("search/FindInFiles"); require("search/FindReplace"); @@ -220,6 +220,7 @@ define(function (require, exports, module) { // Load the initial project after extensions have loaded extensionLoaderPromise.always(function () { // Finish UI initialization + ViewCommandHandlers.restoreFontSize(); var initialProjectPath = ProjectManager.getInitialProjectPath(); ProjectManager.openProject(initialProjectPath).always(function () { _initTest(); diff --git a/src/view/ViewCommandHandlers.js b/src/view/ViewCommandHandlers.js index 4f9bb364263..2be6aafc5cc 100644 --- a/src/view/ViewCommandHandlers.js +++ b/src/view/ViewCommandHandlers.js @@ -78,12 +78,6 @@ define(function (require, exports, module) { */ var LINE_HEIGHT = 1.25; - /** - * @private - * @type {boolean} - */ - var _fontSizePrefsLoaded = false; - /** * @private @@ -95,16 +89,11 @@ define(function (require, exports, module) { /** * @private - * Sets the font size and restores the scroll position as best as possible. - * @param {string} fontSizeStyle A string with the font size and the size unit - * @param {string} lineHeightStyle A string with the line height and a the size unit + * Add the styles used to update the font size + * @param {string} fontSizeStyle A string with the font size and the size unit + * @param {string} lineHeightStyle A string with the line height and a the size unit */ - function _setSizeAndRestoreScroll(fontSizeStyle, lineHeightStyle) { - var editor = EditorManager.getCurrentFullEditor(), - oldWidth = editor._codeMirror.defaultCharWidth(), - oldHeight = editor.getTextHeight(), - scrollPos = editor.getScrollPos(); - + function _addDynamicFontSize(fontSizeStyle, lineHeightStyle) { // It's necessary to inject a new rule to address all editors. _removeDynamicFontSize(); var style = $("").attr("id", DYNAMIC_FONT_STYLE_ID); @@ -112,22 +101,32 @@ define(function (require, exports, module) { "font-size: " + fontSizeStyle + " !important;" + "line-height: " + lineHeightStyle + " !important;}"); $("head").append(style); + } + + /** + * @private + * Sets the font size and restores the scroll position as best as possible. + * @param {string} fontSizeStyle A string with the font size and the size unit + * @param {string} lineHeightStyle A string with the line height and a the size unit + */ + function _setSizeAndRestoreScroll(fontSizeStyle, lineHeightStyle) { + var editor = EditorManager.getCurrentFullEditor(), + oldWidth = editor._codeMirror.defaultCharWidth(), + oldHeight = editor.getTextHeight(), + scrollPos = editor.getScrollPos(); + _addDynamicFontSize(fontSizeStyle, lineHeightStyle); editor.refreshAll(); - // Scroll the document back to its original position, but not on the first load since the position - // was saved with the new height and already been restored. - if (_fontSizePrefsLoaded) { - // Calculate the new scroll based on the old font sizes and scroll position - var newWidth = editor._codeMirror.defaultCharWidth(), - newHeight = editor.getTextHeight(), - deltaX = scrollPos.x / oldWidth, - deltaY = scrollPos.y / oldHeight, - scrollPosX = scrollPos.x + Math.round(deltaX * (newWidth - oldWidth)), - scrollPosY = scrollPos.y + Math.round(deltaY * (newHeight - oldHeight)); + // Calculate the new scroll based on the old font sizes and scroll position + var newWidth = editor._codeMirror.defaultCharWidth(), + newHeight = editor.getTextHeight(), + deltaX = scrollPos.x / oldWidth, + deltaY = scrollPos.y / oldHeight, + scrollPosX = scrollPos.x + Math.round(deltaX * (newWidth - oldWidth)), + scrollPosY = scrollPos.y + Math.round(deltaY * (newHeight - oldHeight)); - editor.setScrollPos(scrollPosX, scrollPosY); - } + editor.setScrollPos(scrollPosX, scrollPosY); } /** @@ -158,6 +157,7 @@ define(function (require, exports, module) { var fsNew = fsOld + (delta * adjustment); var lhNew = lhOld; + if (fsUnits === lhUnits) { lhNew = fsNew * LINE_HEIGHT; if (lhUnits === "px") { @@ -177,6 +177,9 @@ define(function (require, exports, module) { _setSizeAndRestoreScroll(fsStr, lhStr); + PreferencesManager.setViewState("fontSizeString", fsStr); + PreferencesManager.setViewState("lineHeightString", lhStr); + $(exports).triggerHandler("fontSizeChange", [adjustment, fsStr, lhStr]); return true; } @@ -215,14 +218,6 @@ define(function (require, exports, module) { CommandManager.get(Commands.VIEW_DECREASE_FONT_SIZE).setEnabled(true); CommandManager.get(Commands.VIEW_RESTORE_FONT_SIZE).setEnabled(true); } - - // Font Size preferences only need to be loaded one time - if (!_fontSizePrefsLoaded) { - _removeDynamicFontSize(); - _adjustFontSize(PreferencesManager.getViewState("fontSizeAdjustment")); - _fontSizePrefsLoaded = true; - } - } else { // No current document so disable all of the Font Size commands CommandManager.get(Commands.VIEW_INCREASE_FONT_SIZE).setEnabled(false); @@ -231,6 +226,18 @@ define(function (require, exports, module) { } } + /** + * Restores the Font Size and Line Height using the saved strings + */ + function restoreFontSize() { + var fsStr = PreferencesManager.getViewState("fontSizeString"), + lhStr = PreferencesManager.getViewState("lineHeightString"); + + if (fsStr && lhStr) { + _addDynamicFontSize(fsStr, lhStr); + } + } + /** @@ -336,4 +343,6 @@ define(function (require, exports, module) { // Update UI when Brackets finishes loading AppInit.appReady(_updateUI); + + exports.restoreFontSize = restoreFontSize; }); From a5a6394e020acb252be383ae6528b8187a75dd59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Fri, 14 Mar 2014 00:12:16 -0300 Subject: [PATCH 2/7] Fixes after Review --- src/view/ViewCommandHandlers.js | 45 ++++++++++++++++----------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/view/ViewCommandHandlers.js b/src/view/ViewCommandHandlers.js index 2be6aafc5cc..4f5e19a3b1d 100644 --- a/src/view/ViewCommandHandlers.js +++ b/src/view/ViewCommandHandlers.js @@ -91,7 +91,7 @@ define(function (require, exports, module) { * @private * Add the styles used to update the font size * @param {string} fontSizeStyle A string with the font size and the size unit - * @param {string} lineHeightStyle A string with the line height and a the size unit + * @param {string} lineHeightStyle A string with the line height and the size unit */ function _addDynamicFontSize(fontSizeStyle, lineHeightStyle) { // It's necessary to inject a new rule to address all editors. @@ -106,26 +106,28 @@ define(function (require, exports, module) { /** * @private * Sets the font size and restores the scroll position as best as possible. - * @param {string} fontSizeStyle A string with the font size and the size unit - * @param {string} lineHeightStyle A string with the line height and a the size unit + * @param {string=} fontSizeStyle A string with the font size and the size unit + * @param {string=} lineHeightStyle A string with the line height and the size unit */ function _setSizeAndRestoreScroll(fontSizeStyle, lineHeightStyle) { var editor = EditorManager.getCurrentFullEditor(), oldWidth = editor._codeMirror.defaultCharWidth(), - oldHeight = editor.getTextHeight(), - scrollPos = editor.getScrollPos(); - - _addDynamicFontSize(fontSizeStyle, lineHeightStyle); + scrollPos = editor.getScrollPos(), + line = editor._codeMirror.lineAtHeight(scrollPos.y, "local"); + console.log(line); + if (fontSizeStyle && lineHeightStyle) { + _addDynamicFontSize(fontSizeStyle, lineHeightStyle); + } else { + _removeDynamicFontSize(); + } editor.refreshAll(); // Calculate the new scroll based on the old font sizes and scroll position var newWidth = editor._codeMirror.defaultCharWidth(), - newHeight = editor.getTextHeight(), deltaX = scrollPos.x / oldWidth, - deltaY = scrollPos.y / oldHeight, scrollPosX = scrollPos.x + Math.round(deltaX * (newWidth - oldWidth)), - scrollPosY = scrollPos.y + Math.round(deltaY * (newHeight - oldHeight)); - + scrollPosY = editor._codeMirror.heightAtLine(line, "local"); + console.log(scrollPosY); editor.setScrollPos(scrollPosX, scrollPosY); } @@ -177,8 +179,8 @@ define(function (require, exports, module) { _setSizeAndRestoreScroll(fsStr, lhStr); - PreferencesManager.setViewState("fontSizeString", fsStr); - PreferencesManager.setViewState("lineHeightString", lhStr); + PreferencesManager.setViewState("fontSizeStyle", fsStr); + PreferencesManager.setViewState("lineHeightStyle", lhStr); $(exports).triggerHandler("fontSizeChange", [adjustment, fsStr, lhStr]); return true; @@ -186,22 +188,19 @@ define(function (require, exports, module) { /** Increases the font size by 1 */ function _handleIncreaseFontSize() { - if (_adjustFontSize(1)) { - PreferencesManager.setViewState("fontSizeAdjustment", PreferencesManager.getViewState("fontSizeAdjustment") + 1); - } + _adjustFontSize(1); } /** Decreases the font size by 1 */ function _handleDecreaseFontSize() { - if (_adjustFontSize(-1)) { - PreferencesManager.setViewState("fontSizeAdjustment", PreferencesManager.getViewState("fontSizeAdjustment") - 1); - } + _adjustFontSize(-1); } /** Restores the font size to the original size */ function _handleRestoreFontSize() { - _adjustFontSize(-PreferencesManager.getViewState("fontSizeAdjustment")); - PreferencesManager.setViewState("fontSizeAdjustment", 0); + _setSizeAndRestoreScroll(); + PreferencesManager.setViewState("fontSizeStyle", undefined); + PreferencesManager.setViewState("lineHeightStyle", undefined); } @@ -230,8 +229,8 @@ define(function (require, exports, module) { * Restores the Font Size and Line Height using the saved strings */ function restoreFontSize() { - var fsStr = PreferencesManager.getViewState("fontSizeString"), - lhStr = PreferencesManager.getViewState("lineHeightString"); + var fsStr = PreferencesManager.getViewState("fontSizeStyle"), + lhStr = PreferencesManager.getViewState("lineHeightStyle"); if (fsStr && lhStr) { _addDynamicFontSize(fsStr, lhStr); From ebb6b7a925a29617c89e6c283bc21288288529d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Fri, 14 Mar 2014 03:44:56 -0300 Subject: [PATCH 3/7] More changes after review --- src/view/ViewCommandHandlers.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/view/ViewCommandHandlers.js b/src/view/ViewCommandHandlers.js index 4f5e19a3b1d..cbbe81d7d93 100644 --- a/src/view/ViewCommandHandlers.js +++ b/src/view/ViewCommandHandlers.js @@ -94,8 +94,6 @@ define(function (require, exports, module) { * @param {string} lineHeightStyle A string with the line height and the size unit */ function _addDynamicFontSize(fontSizeStyle, lineHeightStyle) { - // It's necessary to inject a new rule to address all editors. - _removeDynamicFontSize(); var style = $("").attr("id", DYNAMIC_FONT_STYLE_ID); style.html(".CodeMirror {" + "font-size: " + fontSizeStyle + " !important;" + @@ -114,11 +112,10 @@ define(function (require, exports, module) { oldWidth = editor._codeMirror.defaultCharWidth(), scrollPos = editor.getScrollPos(), line = editor._codeMirror.lineAtHeight(scrollPos.y, "local"); - console.log(line); + + _removeDynamicFontSize(); if (fontSizeStyle && lineHeightStyle) { _addDynamicFontSize(fontSizeStyle, lineHeightStyle); - } else { - _removeDynamicFontSize(); } editor.refreshAll(); @@ -127,7 +124,7 @@ define(function (require, exports, module) { deltaX = scrollPos.x / oldWidth, scrollPosX = scrollPos.x + Math.round(deltaX * (newWidth - oldWidth)), scrollPosY = editor._codeMirror.heightAtLine(line, "local"); - console.log(scrollPosY); + editor.setScrollPos(scrollPosX, scrollPosY); } @@ -199,8 +196,8 @@ define(function (require, exports, module) { /** Restores the font size to the original size */ function _handleRestoreFontSize() { _setSizeAndRestoreScroll(); - PreferencesManager.setViewState("fontSizeStyle", undefined); - PreferencesManager.setViewState("lineHeightStyle", undefined); + PreferencesManager.setViewState("fontSizeStyle"); + PreferencesManager.setViewState("lineHeightStyle"); } @@ -233,6 +230,7 @@ define(function (require, exports, module) { lhStr = PreferencesManager.getViewState("lineHeightStyle"); if (fsStr && lhStr) { + _removeDynamicFontSize(); _addDynamicFontSize(fsStr, lhStr); } } From 8d0abbd1a1323e130a1f48565e025d2d12a5f634 Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Fri, 14 Mar 2014 00:10:34 -0700 Subject: [PATCH 4/7] Migrate "fontSizeAdjustment" to new view states. --- src/preferences/PreferenceStorage.js | 12 ++++++++++++ src/view/ViewCommandHandlers.js | 21 ++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/preferences/PreferenceStorage.js b/src/preferences/PreferenceStorage.js index 0e7c9cdadbe..202ca36f407 100644 --- a/src/preferences/PreferenceStorage.js +++ b/src/preferences/PreferenceStorage.js @@ -218,6 +218,13 @@ define(function (require, exports, module) { var rule = rules[key]; if (!rule && prefCheckCallback) { rule = prefCheckCallback(key); + } else if (prefCheckCallback) { + // Check whether we have a new preference key-value pair + // for an old preference. + var newRule = prefCheckCallback(key, prefs[key]); + if (newRule) { + rule = _.cloneDeep(newRule); + } } if (!rule) { console.warn("Preferences conversion for ", self._clientID, " has no rule for", key); @@ -238,6 +245,11 @@ define(function (require, exports, module) { manager.set(newKey, prefs[key], options); convertedKeys.push(key); } + } else if (_.isObject(rule)) { + Object.keys(rule).forEach(function (ruleKey) { + manager.set(ruleKey, rule[ruleKey]); + }); + convertedKeys.push(key); } else { complete = false; } diff --git a/src/view/ViewCommandHandlers.js b/src/view/ViewCommandHandlers.js index cbbe81d7d93..2e14951b9fc 100644 --- a/src/view/ViewCommandHandlers.js +++ b/src/view/ViewCommandHandlers.js @@ -323,6 +323,23 @@ define(function (require, exports, module) { _scrollLine(1); } + /** + * @private + * Convert the old "fontSizeAdjustment" preference to the new view states. + * + * @param {string} key The key of the preference to be examined for migration + * of old preferences. Not used since we only have one in this module. + * @param {string} value The value of "fontSizeAdjustment" preference + * @return {Object} - JSON object for the new view states equivalent to + * the old "fontSizeAdjustment" preference. + */ + function _convertToNewViewStates(key, value) { + var fontSize = 12 + value, + newRule = { "fontSizeStyle": fontSize + "px", + "lineHeightStyle": Math.ceil(fontSize * LINE_HEIGHT) + "px" }; + + return newRule; + } // Register command handlers CommandManager.register(Strings.CMD_INCREASE_FONT_SIZE, Commands.VIEW_INCREASE_FONT_SIZE, _handleIncreaseFontSize); @@ -331,9 +348,7 @@ define(function (require, exports, module) { CommandManager.register(Strings.CMD_SCROLL_LINE_UP, Commands.VIEW_SCROLL_LINE_UP, _handleScrollLineUp); CommandManager.register(Strings.CMD_SCROLL_LINE_DOWN, Commands.VIEW_SCROLL_LINE_DOWN, _handleScrollLineDown); - // Initialize the default font size - PreferencesManager.stateManager.definePreference("fontSizeAdjustment", "number", 0); - PreferencesManager.convertPreferences(module, {"fontSizeAdjustment": "user"}, true); + PreferencesManager.convertPreferences(module, {"fontSizeAdjustment": "user"}, true, _convertToNewViewStates); // Update UI when opening or closing a document $(DocumentManager).on("currentDocumentChange", _updateUI); From 25ee23208b94d19f99bbd1d6a56c2ddafccff81c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Fri, 14 Mar 2014 18:26:56 -0300 Subject: [PATCH 5/7] Move the line height to the CSS --- src/styles/brackets_theme_default.less | 4 +- src/view/ViewCommandHandlers.js | 88 ++++++++++---------------- 2 files changed, 35 insertions(+), 57 deletions(-) diff --git a/src/styles/brackets_theme_default.less b/src/styles/brackets_theme_default.less index 4050ac9ef4a..913048ffdbf 100644 --- a/src/styles/brackets_theme_default.less +++ b/src/styles/brackets_theme_default.less @@ -144,10 +144,8 @@ */ .code-font() { color: @content-color; - // line-height must be specified in px not em because the code font and line number font sizes are different. - // Sizing via em will cause the code and line numbers to misalign - line-height: 15px; font-size: 12px; + line-height: 1.25; font-family: "SourceCodePro-Medium", "MS ゴシック", "MS Gothic", monospace; } diff --git a/src/view/ViewCommandHandlers.js b/src/view/ViewCommandHandlers.js index 2e14951b9fc..6fab11fadc9 100644 --- a/src/view/ViewCommandHandlers.js +++ b/src/view/ViewCommandHandlers.js @@ -30,8 +30,6 @@ * Increase Font Size, Decrease Font Size, or Restore Font Size commands. * The 2nd arg to the listener is the amount of the change. The 3rd arg * is a string containing the new font size after applying the change. - * The 4th arg is a string containing the new line height after applying - * the change. */ define(function (require, exports, module) { @@ -91,13 +89,10 @@ define(function (require, exports, module) { * @private * Add the styles used to update the font size * @param {string} fontSizeStyle A string with the font size and the size unit - * @param {string} lineHeightStyle A string with the line height and the size unit */ - function _addDynamicFontSize(fontSizeStyle, lineHeightStyle) { + function _addDynamicFontSize(fontSizeStyle) { var style = $("").attr("id", DYNAMIC_FONT_STYLE_ID); - style.html(".CodeMirror {" + - "font-size: " + fontSizeStyle + " !important;" + - "line-height: " + lineHeightStyle + " !important;}"); + style.html(".CodeMirror { font-size: " + fontSizeStyle + " !important; }"); $("head").append(style); } @@ -105,17 +100,16 @@ define(function (require, exports, module) { * @private * Sets the font size and restores the scroll position as best as possible. * @param {string=} fontSizeStyle A string with the font size and the size unit - * @param {string=} lineHeightStyle A string with the line height and the size unit */ - function _setSizeAndRestoreScroll(fontSizeStyle, lineHeightStyle) { + function _setSizeAndRestoreScroll(fontSizeStyle) { var editor = EditorManager.getCurrentFullEditor(), oldWidth = editor._codeMirror.defaultCharWidth(), scrollPos = editor.getScrollPos(), line = editor._codeMirror.lineAtHeight(scrollPos.y, "local"); _removeDynamicFontSize(); - if (fontSizeStyle && lineHeightStyle) { - _addDynamicFontSize(fontSizeStyle, lineHeightStyle); + if (fontSizeStyle) { + _addDynamicFontSize(fontSizeStyle); } editor.refreshAll(); @@ -135,38 +129,20 @@ define(function (require, exports, module) { * @return {boolean} true if adjustment occurred, false if it did not occur */ function _adjustFontSize(adjustment) { - var fsStyle = $(".CodeMirror").css("font-size"); - var lhStyle = $(".CodeMirror").css("line-height"); - - var validFont = /^[\d\.]+(px|em)$/; + var fsStyle = $(".CodeMirror").css("font-size"), + validFont = /^[\d\.]+(px|em)$/; - // Make sure the font size and line height are expressed in terms - // we can handle (px or em). If not, simply bail. - if (fsStyle.search(validFont) === -1 || lhStyle.search(validFont) === -1) { + // Make sure that the font size is expressed in terms we can handle (px or em). If not, simply bail. + if (fsStyle.search(validFont) === -1) { return false; } // Guaranteed to work by the validation above. - var fsUnits = fsStyle.substring(fsStyle.length - 2, fsStyle.length); - var lhUnits = lhStyle.substring(lhStyle.length - 2, lhStyle.length); - var delta = (fsUnits === "px") ? 1 : 0.1; - - var fsOld = parseFloat(fsStyle.substring(0, fsStyle.length - 2)); - var lhOld = parseFloat(lhStyle.substring(0, lhStyle.length - 2)); - - var fsNew = fsOld + (delta * adjustment); - var lhNew = lhOld; - - if (fsUnits === lhUnits) { - lhNew = fsNew * LINE_HEIGHT; - if (lhUnits === "px") { - // Use integer px value to avoid rounding differences - lhNew = Math.ceil(lhNew); - } - } - - var fsStr = fsNew + fsUnits; - var lhStr = lhNew + lhUnits; + var fsUnits = fsStyle.substring(fsStyle.length - 2, fsStyle.length), + delta = fsUnits === "px" ? 1 : 0.1, + fsOld = parseFloat(fsStyle.substring(0, fsStyle.length - 2)), + fsNew = fsOld + (delta * adjustment), + fsStr = fsNew + fsUnits; // Don't let the font size get too small or too large. The minimum font size is 1px or 0.1em // and the maximum font size is 72px or 7.2em depending on the unit used @@ -174,12 +150,10 @@ define(function (require, exports, module) { return false; } - _setSizeAndRestoreScroll(fsStr, lhStr); - - PreferencesManager.setViewState("fontSizeStyle", fsStr); - PreferencesManager.setViewState("lineHeightStyle", lhStr); + _setSizeAndRestoreScroll(fsStr); + PreferencesManager.setViewState("fontSizeStyle", fsStr); - $(exports).triggerHandler("fontSizeChange", [adjustment, fsStr, lhStr]); + $(exports).triggerHandler("fontSizeChange", [adjustment, fsStr]); return true; } @@ -197,7 +171,6 @@ define(function (require, exports, module) { function _handleRestoreFontSize() { _setSizeAndRestoreScroll(); PreferencesManager.setViewState("fontSizeStyle"); - PreferencesManager.setViewState("lineHeightStyle"); } @@ -226,12 +199,23 @@ define(function (require, exports, module) { * Restores the Font Size and Line Height using the saved strings */ function restoreFontSize() { - var fsStr = PreferencesManager.getViewState("fontSizeStyle"), - lhStr = PreferencesManager.getViewState("lineHeightStyle"); - - if (fsStr && lhStr) { + var fsStyle = PreferencesManager.getViewState("fontSizeStyle"), + fsAdjustment = PreferencesManager.getViewState("fontSizeAdjustment"); + + if (fsAdjustment) { + // Always remove the old view state even if we also have the new view state. + PreferencesManager.setViewState("fontSizeAdjustment"); + + if (!fsStyle) { + // Migrate the old view state to the new one. + fsStyle = (12 + fsAdjustment) + "px"; + PreferencesManager.setViewState("fontSizeStyle", fsStyle); + } + } + + if (fsStyle) { _removeDynamicFontSize(); - _addDynamicFontSize(fsStr, lhStr); + _addDynamicFontSize(fsStyle); } } @@ -334,11 +318,7 @@ define(function (require, exports, module) { * the old "fontSizeAdjustment" preference. */ function _convertToNewViewStates(key, value) { - var fontSize = 12 + value, - newRule = { "fontSizeStyle": fontSize + "px", - "lineHeightStyle": Math.ceil(fontSize * LINE_HEIGHT) + "px" }; - - return newRule; + return { "fontSizeStyle": (12 + value) + "px" }; } // Register command handlers From bb3e75d3916039341e7a71fba9f6796fc953c573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Fri, 14 Mar 2014 19:12:58 -0300 Subject: [PATCH 6/7] Fixes after last review --- src/view/ViewCommandHandlers.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/view/ViewCommandHandlers.js b/src/view/ViewCommandHandlers.js index 6fab11fadc9..8061187cae5 100644 --- a/src/view/ViewCommandHandlers.js +++ b/src/view/ViewCommandHandlers.js @@ -56,7 +56,7 @@ define(function (require, exports, module) { * @const * @private * The smallest font size in pixels - * @type {int} + * @type {number} */ var MIN_FONT_SIZE = 1; @@ -64,17 +64,17 @@ define(function (require, exports, module) { * @const * @private * The largest font size in pixels - * @type {int} + * @type {number} */ var MAX_FONT_SIZE = 72; /** * @const * @private - * The ratio of line-height to font-size when they use the same units - * @type {float} + * The default font size used only to convert the old fontSizeAdjustment view state to the new fontSizeStyle + * @type {number} */ - var LINE_HEIGHT = 1.25; + var DEFAULT_FONT_SIZE = 12; /** @@ -125,7 +125,7 @@ define(function (require, exports, module) { /** * @private * Increases or decreases the editor's font size. - * @param {number} adjustment Negative number to make the font smaller; positive number to make it bigger + * @param {number} adjustment Negative number to make the font smaller; positive number to make it bigger * @return {boolean} true if adjustment occurred, false if it did not occur */ function _adjustFontSize(adjustment) { @@ -196,7 +196,8 @@ define(function (require, exports, module) { } /** - * Restores the Font Size and Line Height using the saved strings + * Restores the font size using the saved style and migrates the old fontSizeAdjustment + * view state to the new fontSizeStyle, when required */ function restoreFontSize() { var fsStyle = PreferencesManager.getViewState("fontSizeStyle"), @@ -208,7 +209,7 @@ define(function (require, exports, module) { if (!fsStyle) { // Migrate the old view state to the new one. - fsStyle = (12 + fsAdjustment) + "px"; + fsStyle = (DEFAULT_FONT_SIZE + fsAdjustment) + "px"; PreferencesManager.setViewState("fontSizeStyle", fsStyle); } } @@ -309,16 +310,16 @@ define(function (require, exports, module) { /** * @private - * Convert the old "fontSizeAdjustment" preference to the new view states. + * Convert the old "fontSizeAdjustment" preference to the new view state. * - * @param {string} key The key of the preference to be examined for migration + * @param {string} key The key of the preference to be examined for migration * of old preferences. Not used since we only have one in this module. - * @param {string} value The value of "fontSizeAdjustment" preference - * @return {Object} - JSON object for the new view states equivalent to + * @param {string} value The value of "fontSizeAdjustment" preference + * @return {Object} JSON object for the new view state equivalent to * the old "fontSizeAdjustment" preference. */ function _convertToNewViewStates(key, value) { - return { "fontSizeStyle": (12 + value) + "px" }; + return { "fontSizeStyle": (DEFAULT_FONT_SIZE + value) + "px" }; } // Register command handlers From 3959dd00caf762a71a6f2b1e1883e71cfeaaf224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Fri, 14 Mar 2014 20:01:59 -0300 Subject: [PATCH 7/7] convert to new view state (with no s) --- src/view/ViewCommandHandlers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/view/ViewCommandHandlers.js b/src/view/ViewCommandHandlers.js index 8061187cae5..f233ccb9764 100644 --- a/src/view/ViewCommandHandlers.js +++ b/src/view/ViewCommandHandlers.js @@ -318,7 +318,7 @@ define(function (require, exports, module) { * @return {Object} JSON object for the new view state equivalent to * the old "fontSizeAdjustment" preference. */ - function _convertToNewViewStates(key, value) { + function _convertToNewViewState(key, value) { return { "fontSizeStyle": (DEFAULT_FONT_SIZE + value) + "px" }; } @@ -329,7 +329,7 @@ define(function (require, exports, module) { CommandManager.register(Strings.CMD_SCROLL_LINE_UP, Commands.VIEW_SCROLL_LINE_UP, _handleScrollLineUp); CommandManager.register(Strings.CMD_SCROLL_LINE_DOWN, Commands.VIEW_SCROLL_LINE_DOWN, _handleScrollLineDown); - PreferencesManager.convertPreferences(module, {"fontSizeAdjustment": "user"}, true, _convertToNewViewStates); + PreferencesManager.convertPreferences(module, {"fontSizeAdjustment": "user"}, true, _convertToNewViewState); // Update UI when opening or closing a document $(DocumentManager).on("currentDocumentChange", _updateUI);