-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix #3478: Persistent highlight is taller than transient highlight #3568
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,15 @@ define(function (require, exports, module) { | |
* @type {int} | ||
*/ | ||
var MAX_FONT_SIZE = 72; | ||
|
||
|
||
/** | ||
* @const | ||
* @private | ||
* The proportion between the font-size and the line-height in pixels | ||
* @type {float} | ||
*/ | ||
var LINE_HEIGHT = 1.25; | ||
|
||
/** | ||
* @private | ||
* @type {PreferenceStorage} | ||
|
@@ -147,28 +155,19 @@ define(function (require, exports, module) { | |
// Guaranteed to work by the validation above. | ||
var fsUnits = fsStyle.substring(fsStyle.length - 2, fsStyle.length); | ||
var lhUnits = lhStyle.substring(lhStyle.length - 2, lhStyle.length); | ||
|
||
var fsOld = parseFloat(fsStyle.substring(0, fsStyle.length - 2)); | ||
var lhOld = parseFloat(lhStyle.substring(0, lhStyle.length - 2)); | ||
|
||
var fsDelta = (fsUnits === "px") ? adjustment : (0.1 * adjustment); | ||
var lhDelta = (lhUnits === "px") ? adjustment : (0.1 * adjustment); | ||
|
||
var fsNew = fsOld + fsDelta; | ||
var lhNew = lhOld + lhDelta; | ||
var delta = (fsUnits === "px") ? 1 : 0.1; | ||
|
||
var fsStr = fsNew + fsUnits; | ||
var lhStr = lhNew + lhUnits; | ||
|
||
// Don't let the font size get too small. | ||
if ((fsUnits === "px" && fsNew < MIN_FONT_SIZE) || | ||
(fsUnits === "em" && fsNew < (MIN_FONT_SIZE * 0.1))) { | ||
return false; | ||
} | ||
var fsOld = parseFloat(fsStyle.substring(0, fsStyle.length - 2)); | ||
var lhOld = parseFloat(lhStyle.substring(0, lhStyle.length - 2)); | ||
|
||
var fsNew = fsOld + (delta * adjustment); | ||
var lhNew = (fsUnits === lhUnits) ? fsNew * LINE_HEIGHT : lhOld; | ||
|
||
// Don't let the font size get too large. | ||
if ((fsUnits === "px" && fsNew > MAX_FONT_SIZE) || | ||
(fsUnits === "em" && fsNew > (MAX_FONT_SIZE * 0.1))) { | ||
var fsStr = fsNew + fsUnits; | ||
var lhStr = lhNew + lhUnits; | ||
|
||
// Don't let the font size get too small or too large. | ||
if (fsNew < MIN_FONT_SIZE * delta || fsNew > MAX_FONT_SIZE * delta) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maximum px size is 72, otherwise 7.2. This works for px and em, but if anyone changes units to anything else, the results may not be desirable. Maybe this should check for units type (like it did before). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing would actually work for other units, and that is why the code is returned on line 151 when the units aren't px or em, so this check wasn't that necessary. If a new font size unit would be introduced the whole code would need to be updated to support it, so I don't think this is an issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, this is a bit cryptic, so please explain the 72 vs 7.2 in a comment. |
||
return false; | ||
} | ||
|
||
|
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 just noticed that his comment is not quite correct. The operands are reversed, and it's not in pixels (it's a ratio).
It should be "The ratio of line-height to font-size".
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.
Right, I intended to use it just for px, but then I realized that it would be required for ems too, when both units are ems. I'll update this comment 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.
Even better: "The ratio of line-height to font-size when font-size is in 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.
Actually it is used when both font-size and line-height are in px or ems, and is not when they are different. If the font-size is on px and the line-height in ems, the line height doesn't change. So the previous one is more accurate.
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.
It still bugs me that the operands are reversed. How about: "The ratio of line-height to font-size when the use the same units"