-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix fontSizeChange event for Restore Font Size command #7443
Conversation
@@ -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]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This event is now triggered twice. We should remove the line 163.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lkcampbell If you want to trigger the event here, then you need to remove the one in _adjustFontSize
. Otherwise, we're triggering twice for increase/decrease font size scenarios.
Also, you are passing the delta in font size whereas @TomMalbran was passing the actual font size in his changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fontSizeChange always sends the adjustment and the new font size string. This works fine for font sizes in px, but would fail with font sizes in ems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lkcampbell and @TomMalbran
I was expecting to have one line addition to _handleRestoreFontSize
to trigger event with the following line.
$(exports).triggerHandler("fontSizeChange", [adjustment, DEFAULT_FONT_SIZE + "px"]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That won't work because we don't have the adjustment
defined in _handleRestoreFontSize
so we need to calculate it in the same way as @lkcampbell did. And since we need to calculate it, using the css style as the font size string is better since we then don't depend on knowing the default font-size or the units and the code will just work if we decide to change any of those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomMalbran is saying your current implementation is better, you just need to remove the other trigger event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomMalbran, just because I am curious. Has there ever been a situation where we are using a font size that uses ems as its units? I mean, I know that code has been in there for a while but does it ever actually get used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want it to work with ems too? The rest of the code works with ems too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first one who implemented this code did it like that. But yes, the default font-size never actually changed. Anyway, maybe in the future it could change or a theme could use a different font-size it or it could be edited by a preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should work for both px and ems
delta = /em$/.test(oldFontSize) ? 10 : 1;
adjustment = parseInt((parseFloat(newFontSize) - parseFloat(oldFontSize)) * delta, 10);
@lkcampbell Thanks for fixing this. I am a bit busy these days. |
Sorry guys, let me fix it. I was wondering why it seemed to be firing off twice. @RaymondLim's way looks much better than mine. |
@RaymondLim and @TomMalbran, code review changes committed. |
@@ -113,6 +117,11 @@ define(function (require, exports, module) { | |||
} | |||
editor.refreshAll(); | |||
|
|||
delta = /em$/.test(oldFontSize) ? 10 : 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think delta for em
is 0.1, not 10. Look at the one used in _adjustFontSize
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RaymondLim it's a 10:1 ratio for ems:pixel. The code you refer to is a 1:0.1 ratio which equates to 10:1. If the units are in ems, we need to multiply them by 10 to convert them into pixels. I think keeping everything in pixels is the best bet even if we are using ems because, I think, the calculated font-size always comes back in pixels regardless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, if I am being completely honest with both of you, I haven't tested this with setting the font size to em units...so, I probably should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomMalbran, if the value of $(".CodeMirror").css("font-size")
always comes back in pixels, and I think it does, we don't have to check for ems, correct? Or am I wrong about it always coming back as pixels?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that on chrome it does return the calculated value, but not
sure about other browsers or if the api might change once chrome is able to
return the original value.
Anyway this is just for completition since the rest of the code aaaumes it
can be either value. We probably won't be able to test it. But if we don't
add it here we should assume that we alwaya get px and remove the em bit
and be sure that it will work on other browsers. Ao maybe that is for
another clean up, and I think that it might have been discussed before.
El 08/04/2014 02:09, "Lance Campbell" notifications@github.com escribió:
In src/view/ViewCommandHandlers.js:
@@ -113,6 +117,11 @@ define(function (require, exports, module) {
}
editor.refreshAll();
delta = /em$/.test(oldFontSize) ? 10 : 1;
@TomMalbran https://github.com/TomMalbran, if the value of
$(".CodeMirror").css("font-size") always comes back in pixels, and I
think it does, we don't have to check for ems, correct? Or am I wrong about
it always coming back as pixels?Reply to this email directly or view it on GitHubhttps://github.com//pull/7443/files#r11376458
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomMalbran, okay, sounds good. Thanks for addressing all my questions.
@RaymondLim, I tested the code setting the font size to em units. It works; however, as @TomMalbran and I were discussing, that branch of the code never gets run. Currently, all font sizes contained in variables oldFontSize
and newFontSize
are always in terms of pixels. I addressed your question on the math of em ratios as best I could so I think this code review is done. I have nothing to change in the code at this point.
@RaymondLim and @TomMalbran, Code Review notes reviewed. Nothing to change in the code as far as I can tell. |
@RaymondLim and @TomMalbran, hold off for a bit. I have one more thing I want to test. I will let you know when I am done. |
@RaymondLim and @TomMalbran, almost missed a critical little detail :). Code ready for next code review. |
Making a note here to remind myself. I need to put in some Unit Tests for this event in the near future so we don't have any future regressions. |
Looks good. Merging. |
Fix fontSizeChange event for Restore Font Size command
Some of the recent changes to font size adjustment broke the fontSizeChange event when the Restore Font Size command is used. This fix makes the event fire correctly again.