Merge pull request #3033 from thelounge/xpaw/fix-input-overflow
Fix up textarea growing to avoid rounding issues in Chrome
This commit is contained in:
commit
e4209714ee
@ -1983,7 +1983,7 @@ part/quit messages where we don't load previews (adds a blank line otherwise) */
|
|||||||
min-height: 19px; /* Required when computing input height at char deletion */
|
min-height: 19px; /* Required when computing input height at char deletion */
|
||||||
height: 19px;
|
height: 19px;
|
||||||
max-height: 95px; /* min-height/height x number of lines maximum */
|
max-height: 95px; /* min-height/height x number of lines maximum */
|
||||||
line-height: 19px /* should match height */;
|
line-height: 19px; /* should match height */
|
||||||
outline: none;
|
outline: none;
|
||||||
margin: 5px;
|
margin: 5px;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
@ -82,23 +82,22 @@ $(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function resetInputHeight(input) {
|
function resetInputHeight(input) {
|
||||||
input.style.height = input.style.minHeight;
|
input.style.height = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const input = $("#input")
|
const input = $("#input")
|
||||||
.on("input", function() {
|
.on("input", function() {
|
||||||
const style = window.getComputedStyle(this);
|
const style = window.getComputedStyle(this);
|
||||||
|
const lineHeight = parseFloat(style.lineHeight, 10) || 1;
|
||||||
|
|
||||||
// Start by resetting height before computing as scrollHeight does not
|
// Start by resetting height before computing as scrollHeight does not
|
||||||
// decrease when deleting characters
|
// decrease when deleting characters
|
||||||
resetInputHeight(this);
|
resetInputHeight(this);
|
||||||
|
|
||||||
this.style.height = Math.min(
|
// Use scrollHeight to calculate how many lines there are in input, and ceil the value
|
||||||
Math.round(window.innerHeight - 100), // prevent overflow
|
// because some browsers tend to incorrently round the values when using high density
|
||||||
this.scrollHeight
|
// displays or using page zoom feature
|
||||||
+ Math.round(parseFloat(style.borderTopWidth) || 0)
|
this.style.height = Math.ceil(this.scrollHeight / lineHeight) * lineHeight + "px";
|
||||||
+ Math.round(parseFloat(style.borderBottomWidth) || 0)
|
|
||||||
) + "px";
|
|
||||||
|
|
||||||
chat.find(".chan.active .chat").trigger("keepToBottom"); // fix growing
|
chat.find(".chan.active .chat").trigger("keepToBottom"); // fix growing
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user