diff --git a/src/view/ViewCommandHandlers.js b/src/view/ViewCommandHandlers.js index f233ccb9764..b2e65cfd798 100644 --- a/src/view/ViewCommandHandlers.js +++ b/src/view/ViewCommandHandlers.js @@ -102,10 +102,14 @@ define(function (require, exports, module) { * @param {string=} fontSizeStyle A string with the font size and the size unit */ function _setSizeAndRestoreScroll(fontSizeStyle) { - var editor = EditorManager.getCurrentFullEditor(), - oldWidth = editor._codeMirror.defaultCharWidth(), - scrollPos = editor.getScrollPos(), - line = editor._codeMirror.lineAtHeight(scrollPos.y, "local"); + var editor = EditorManager.getCurrentFullEditor(), + oldWidth = editor._codeMirror.defaultCharWidth(), + oldFontSize = $(".CodeMirror").css("font-size"), + newFontSize = "", + delta = 0, + adjustment = 0, + scrollPos = editor.getScrollPos(), + line = editor._codeMirror.lineAtHeight(scrollPos.y, "local"); _removeDynamicFontSize(); if (fontSizeStyle) { @@ -113,6 +117,14 @@ define(function (require, exports, module) { } editor.refreshAll(); + delta = /em$/.test(oldFontSize) ? 10 : 1; + newFontSize = $(".CodeMirror").css("font-size"); + adjustment = parseInt((parseFloat(newFontSize) - parseFloat(oldFontSize)) * delta, 10); + + if (adjustment) { + $(exports).triggerHandler("fontSizeChange", [adjustment, newFontSize]); + } + // Calculate the new scroll based on the old font sizes and scroll position var newWidth = editor._codeMirror.defaultCharWidth(), deltaX = scrollPos.x / oldWidth, @@ -153,7 +165,6 @@ define(function (require, exports, module) { _setSizeAndRestoreScroll(fsStr); PreferencesManager.setViewState("fontSizeStyle", fsStr); - $(exports).triggerHandler("fontSizeChange", [adjustment, fsStr]); return true; }