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 #7443 from lkcampbell/fix-font-size-event
Browse files Browse the repository at this point in the history
Fix fontSizeChange event for Restore Font Size command
  • Loading branch information
RaymondLim committed Apr 8, 2014
2 parents 9111c08 + 1547c8b commit b254d6c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/view/ViewCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,29 @@ 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) {
_addDynamicFontSize(fontSizeStyle);
}
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,
Expand Down Expand Up @@ -153,7 +165,6 @@ define(function (require, exports, module) {
_setSizeAndRestoreScroll(fsStr);
PreferencesManager.setViewState("fontSizeStyle", fsStr);

$(exports).triggerHandler("fontSizeChange", [adjustment, fsStr]);
return true;
}

Expand Down

0 comments on commit b254d6c

Please sign in to comment.