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

Use integer line-height to avoid rounding differences #3849

Merged
merged 4 commits into from
May 17, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/view/ViewCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ define(function (require, exports, module) {
* The ratio of line-height to font-size when they use the same units
* @type {float}
*/
var LINE_HEIGHT = 1.3;
var LINE_HEIGHT = 1.25;

/**
* @private
Expand Down Expand Up @@ -171,7 +171,14 @@ define(function (require, exports, module) {
var lhOld = parseFloat(lhStyle.substring(0, lhStyle.length - 2));

var fsNew = fsOld + (delta * adjustment);
var lhNew = (fsUnits === lhUnits) ? fsNew * LINE_HEIGHT : lhOld;
var lhNew = lhOld;
if (fsUnits === lhUnits) {
lhNew = fsNew * LINE_HEIGHT;
if (lhUnits === "px") {
// Use integer px value to avoid rounding differences
lhNew = Math.ceil(lhNew);
}
}

var fsStr = fsNew + fsUnits;
var lhStr = lhNew + lhUnits;
Expand Down
6 changes: 3 additions & 3 deletions test/spec/ViewCommandHandlers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ define(function (require, exports, module) {
});

it("should keep the same font size when opening another document", function () {
var promise, expectedSize, editor;
var promise, originalSize, editor;

runs(function () {
editor = EditorManager.getCurrentFullEditor();
expectedSize = editor.getTextHeight() + 1;
originalSize = editor.getTextHeight();

promise = CommandManager.execute(Commands.VIEW_INCREASE_FONT_SIZE);
waitsForDone(promise, "Increase font size");
Expand All @@ -139,7 +139,7 @@ define(function (require, exports, module) {

runs(function () {
editor = EditorManager.getCurrentFullEditor();
expect(editor.getTextHeight()).toBe(expectedSize);
expect(editor.getTextHeight()).toBeGreaterThan(originalSize);
});

// This must be in the last spec in the suite.
Expand Down