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

Fix fontSizeChange event for Restore Font Size command #7443

Merged
merged 3 commits into from
Apr 8, 2014
Merged

Fix fontSizeChange event for Restore Font Size command #7443

merged 3 commits into from
Apr 8, 2014

Conversation

lkcampbell
Copy link
Contributor

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.

@@ -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]);
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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"]);

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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);

@TomMalbran
Copy link
Contributor

@lkcampbell Thanks for fixing this. I am a bit busy these days.

@lkcampbell
Copy link
Contributor Author

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.

@lkcampbell
Copy link
Contributor Author

@RaymondLim and @TomMalbran, code review changes committed.

@@ -113,6 +117,11 @@ define(function (require, exports, module) {
}
editor.refreshAll();

delta = /em$/.test(oldFontSize) ? 10 : 1;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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
.

Copy link
Contributor Author

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.

@lkcampbell
Copy link
Contributor Author

@RaymondLim and @TomMalbran, Code Review notes reviewed. Nothing to change in the code as far as I can tell.

@lkcampbell
Copy link
Contributor Author

@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.

@lkcampbell
Copy link
Contributor Author

@RaymondLim and @TomMalbran, almost missed a critical little detail :). Code ready for next code review.

@lkcampbell
Copy link
Contributor Author

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.

@njx njx added this to the Release #38 milestone Apr 8, 2014
@RaymondLim
Copy link
Contributor

Looks good. Merging.

RaymondLim added a commit that referenced this pull request Apr 8, 2014
Fix fontSizeChange event for Restore Font Size command
@RaymondLim RaymondLim merged commit b254d6c into adobe:master Apr 8, 2014
@lkcampbell lkcampbell deleted the fix-font-size-event branch April 9, 2014 01:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants