From 34dbe00cade6dba6849ead18d826bfb68e8f663f Mon Sep 17 00:00:00 2001 From: Lance Campbell Date: Mon, 7 Apr 2014 18:33:33 -0700 Subject: [PATCH 1/3] Fix fontSizeChange event for Restore Font Size command --- src/view/ViewCommandHandlers.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/view/ViewCommandHandlers.js b/src/view/ViewCommandHandlers.js index f233ccb9764..8319666b2a1 100644 --- a/src/view/ViewCommandHandlers.js +++ b/src/view/ViewCommandHandlers.js @@ -102,10 +102,13 @@ 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(), + newFontSize = "", + oldFontSize = $(".CodeMirror").css("font-size"), + fontSizeChange = 0, + scrollPos = editor.getScrollPos(), + line = editor._codeMirror.lineAtHeight(scrollPos.y, "local"); _removeDynamicFontSize(); if (fontSizeStyle) { @@ -113,6 +116,10 @@ define(function (require, exports, module) { } editor.refreshAll(); + newFontSize = $(".CodeMirror").css("font-size"); + fontSizeChange = parseInt(newFontSize, 10) - parseInt(oldFontSize, 10); + $(exports).triggerHandler("fontSizeChange", [fontSizeChange, newFontSize]); + // Calculate the new scroll based on the old font sizes and scroll position var newWidth = editor._codeMirror.defaultCharWidth(), deltaX = scrollPos.x / oldWidth, From 479ba7b8ef39c44a1cbaf8acb93f331b888724d0 Mon Sep 17 00:00:00 2001 From: Lance Campbell Date: Mon, 7 Apr 2014 21:12:41 -0700 Subject: [PATCH 2/3] Stop event from firing twice. Make code work with em units. --- src/view/ViewCommandHandlers.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/view/ViewCommandHandlers.js b/src/view/ViewCommandHandlers.js index 8319666b2a1..2e7806d4e50 100644 --- a/src/view/ViewCommandHandlers.js +++ b/src/view/ViewCommandHandlers.js @@ -102,13 +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(), - newFontSize = "", - oldFontSize = $(".CodeMirror").css("font-size"), - fontSizeChange = 0, - 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) { @@ -116,9 +117,10 @@ define(function (require, exports, module) { } editor.refreshAll(); + delta = /em$/.test(oldFontSize) ? 10 : 1; newFontSize = $(".CodeMirror").css("font-size"); - fontSizeChange = parseInt(newFontSize, 10) - parseInt(oldFontSize, 10); - $(exports).triggerHandler("fontSizeChange", [fontSizeChange, newFontSize]); + adjustment = parseInt((parseFloat(newFontSize) - parseFloat(oldFontSize)) * delta, 10); + $(exports).triggerHandler("fontSizeChange", [adjustment, newFontSize]); // Calculate the new scroll based on the old font sizes and scroll position var newWidth = editor._codeMirror.defaultCharWidth(), @@ -160,7 +162,6 @@ define(function (require, exports, module) { _setSizeAndRestoreScroll(fsStr); PreferencesManager.setViewState("fontSizeStyle", fsStr); - $(exports).triggerHandler("fontSizeChange", [adjustment, fsStr]); return true; } From 1547c8b6e59aa82eaec4f4c98a814d7648d7e4a8 Mon Sep 17 00:00:00 2001 From: Lance Campbell Date: Tue, 8 Apr 2014 08:51:15 -0700 Subject: [PATCH 3/3] Only fire event when there is an adjustment in font size --- src/view/ViewCommandHandlers.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/view/ViewCommandHandlers.js b/src/view/ViewCommandHandlers.js index 2e7806d4e50..b2e65cfd798 100644 --- a/src/view/ViewCommandHandlers.js +++ b/src/view/ViewCommandHandlers.js @@ -120,7 +120,10 @@ define(function (require, exports, module) { delta = /em$/.test(oldFontSize) ? 10 : 1; newFontSize = $(".CodeMirror").css("font-size"); adjustment = parseInt((parseFloat(newFontSize) - parseFloat(oldFontSize)) * delta, 10); - $(exports).triggerHandler("fontSizeChange", [adjustment, newFontSize]); + + 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(),