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

Commit b254d6c

Browse files
committed
Merge pull request #7443 from lkcampbell/fix-font-size-event
Fix fontSizeChange event for Restore Font Size command
2 parents 9111c08 + 1547c8b commit b254d6c

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/view/ViewCommandHandlers.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,29 @@ define(function (require, exports, module) {
102102
* @param {string=} fontSizeStyle A string with the font size and the size unit
103103
*/
104104
function _setSizeAndRestoreScroll(fontSizeStyle) {
105-
var editor = EditorManager.getCurrentFullEditor(),
106-
oldWidth = editor._codeMirror.defaultCharWidth(),
107-
scrollPos = editor.getScrollPos(),
108-
line = editor._codeMirror.lineAtHeight(scrollPos.y, "local");
105+
var editor = EditorManager.getCurrentFullEditor(),
106+
oldWidth = editor._codeMirror.defaultCharWidth(),
107+
oldFontSize = $(".CodeMirror").css("font-size"),
108+
newFontSize = "",
109+
delta = 0,
110+
adjustment = 0,
111+
scrollPos = editor.getScrollPos(),
112+
line = editor._codeMirror.lineAtHeight(scrollPos.y, "local");
109113

110114
_removeDynamicFontSize();
111115
if (fontSizeStyle) {
112116
_addDynamicFontSize(fontSizeStyle);
113117
}
114118
editor.refreshAll();
115119

120+
delta = /em$/.test(oldFontSize) ? 10 : 1;
121+
newFontSize = $(".CodeMirror").css("font-size");
122+
adjustment = parseInt((parseFloat(newFontSize) - parseFloat(oldFontSize)) * delta, 10);
123+
124+
if (adjustment) {
125+
$(exports).triggerHandler("fontSizeChange", [adjustment, newFontSize]);
126+
}
127+
116128
// Calculate the new scroll based on the old font sizes and scroll position
117129
var newWidth = editor._codeMirror.defaultCharWidth(),
118130
deltaX = scrollPos.x / oldWidth,
@@ -153,7 +165,6 @@ define(function (require, exports, module) {
153165
_setSizeAndRestoreScroll(fsStr);
154166
PreferencesManager.setViewState("fontSizeStyle", fsStr);
155167

156-
$(exports).triggerHandler("fontSizeChange", [adjustment, fsStr]);
157168
return true;
158169
}
159170

0 commit comments

Comments
 (0)