Skip to content

Commit

Permalink
Merge pull request #11 from sourcelair/issue/9
Browse files Browse the repository at this point in the history
Fixed incorrect row/column calculation in Firefox
  • Loading branch information
akalipetis committed Nov 24, 2014
2 parents c6a7e15 + 37be8e0 commit 510990c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
56 changes: 29 additions & 27 deletions addons/fit/fit.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,44 @@
}
})(function (Xterm) {
Xterm.prototype.proposeGeometry = function () {
var container = this.rowContainer,
var parentElementStyle = window.getComputedStyle(this.element.parentElement),
parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')),
parentElementWidth = parseInt(parentElementStyle.getPropertyValue('width')),
elementStyle = window.getComputedStyle(this.element),
elementPaddingVer = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom')),
elementPaddingHor = parseInt(elementStyle.getPropertyValue('padding-right')) + parseInt(elementStyle.getPropertyValue('padding-left')),
availableHeight = parentElementHeight - elementPaddingVer,
availableWidth = parentElementWidth - elementPaddingHor,
container = this.rowContainer,
subjectRow = this.rowContainer.firstElementChild,
contentBuffer = subjectRow.innerHTML,
characterHeight,
rows,
contentBuffer,
characterWidth,
cols;
cols,
geometry;

subjectRow.style.display = 'inline';

contentBuffer = subjectRow.innerHTML;

subjectRow.innerHTML = ' '; /* Arbitrary character to calculate its dimensions */
subjectRow.innerHTML = 'W'; // Common character for measuring width, although on monospace
characterWidth = parseInt(subjectRow.offsetWidth);
subjectRow.style.display = ''; // Revert style before calculating height, since they differ.
characterHeight = parseInt(subjectRow.offsetHeight);
subjectRow.innerHTML = contentBuffer;

subjectRow.style.display = '';

cols = container.offsetWidth / characterWidth;
cols = parseInt(cols);

var parentElementStyle = window.getComputedStyle(this.element.parentElement),
parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')),
elementStyle = window.getComputedStyle(this.element),
elementPadding = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom')),
availableHeight = parentElementHeight - elementPadding,
rowHeight = this.rowContainer.firstElementChild.offsetHeight;

rows = parseInt(availableHeight / rowHeight);

subjectRow.innerHTML = contentBuffer; /* Replace original content */

var geometry = {
'cols': cols,
'rows': rows
};
rows = parseInt(availableHeight / characterHeight);
/*
* The following hack takes place in order to get "fit" work properly
* in Mozilla Firefox.
* Most probably, because of a dimension calculation bug, Firefox
* calculates the width to be 1px less than it is actually drawn on
* screen.
*/
if (navigator.userAgent.match(/Firefox/)) {
characterWidth++;
}
cols = parseInt(availableWidth / characterWidth);

geometry = {cols: cols, rows: rows};
return geometry;
};

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "xterm.js",
"version": "0.25",
"version": "0.26",
"ignore": ["demo", "docs", "test", ".gitignore"]
}
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
# built documents.
#
# The short X.Y version.
version = '0.25'
version = '0.26'
# The full version, including alpha/beta/rc tags.
release = '0.25 Alpha'
release = '0.26 Alpha'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down

0 comments on commit 510990c

Please sign in to comment.