use getBoundingClientRect for measuring text size
needed because on chrome 17+ line heights can be fractional
This commit is contained in:
parent
59ddc64d3d
commit
9a45c466ae
2 changed files with 39 additions and 3 deletions
|
|
@ -103,7 +103,7 @@ var Text = function(parentEl) {
|
||||||
lineHeight : 1
|
lineHeight : 1
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$measureSizes = function() {
|
this.$measureSizes = useragent.isIE || useragent.isOldGecko ? function() {
|
||||||
var n = 1000;
|
var n = 1000;
|
||||||
if (!this.$measureNode) {
|
if (!this.$measureNode) {
|
||||||
var measureNode = this.$measureNode = dom.createElement("div");
|
var measureNode = this.$measureNode = dom.createElement("div");
|
||||||
|
|
@ -130,7 +130,6 @@ var Text = function(parentEl) {
|
||||||
container = container.parentNode;
|
container = container.parentNode;
|
||||||
container.appendChild(measureNode);
|
container.appendChild(measureNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Size and width can be null if the editor is not visible or
|
// Size and width can be null if the editor is not visible or
|
||||||
|
|
@ -150,7 +149,42 @@ var Text = function(parentEl) {
|
||||||
|
|
||||||
// Size and width can be null if the editor is not visible or
|
// Size and width can be null if the editor is not visible or
|
||||||
// detached from the document
|
// detached from the document
|
||||||
if (size.width == 0 && size.height == 0)
|
if (size.width == 0 || size.height == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
: function() {
|
||||||
|
if (!this.$measureNode) {
|
||||||
|
var measureNode = this.$measureNode = dom.createElement("div");
|
||||||
|
var style = measureNode.style;
|
||||||
|
|
||||||
|
style.width = style.height = "auto";
|
||||||
|
style.left = style.top = -100 + "px";
|
||||||
|
|
||||||
|
style.visibility = "hidden";
|
||||||
|
style.position = "fixed";
|
||||||
|
style.overflow = "visible";
|
||||||
|
style.whiteSpace = "nowrap";
|
||||||
|
|
||||||
|
measureNode.innerHTML = "X";
|
||||||
|
|
||||||
|
var container = this.element.parentNode;
|
||||||
|
while (!dom.hasCssClass(container, "ace_editor"))
|
||||||
|
container = container.parentNode;
|
||||||
|
container.appendChild(measureNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
var rect = this.$measureNode.getBoundingClientRect();
|
||||||
|
|
||||||
|
var size = {
|
||||||
|
height: rect.height,
|
||||||
|
width: rect.width
|
||||||
|
};
|
||||||
|
|
||||||
|
// Size and width can be null if the editor is not visible or
|
||||||
|
// detached from the document
|
||||||
|
if (size.width == 0 || size.height == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,8 @@ var ScrollBar = function(parent) {
|
||||||
this.inner.style.height = height + "px";
|
this.inner.style.height = height + "px";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: on chrome 17+ after for small zoom levels after this function
|
||||||
|
// this.element.scrollTop != scrollTop which makes page to scroll up.
|
||||||
this.setScrollTop = function(scrollTop) {
|
this.setScrollTop = function(scrollTop) {
|
||||||
this.element.scrollTop = scrollTop;
|
this.element.scrollTop = scrollTop;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue