Fix imposter issues with <input type="text">

This commit is contained in:
toasted-nutbread 2019-08-31 15:10:46 -04:00
parent ad0dca7bb1
commit 9b46fe70de

View File

@ -30,7 +30,7 @@ function docOffsetCalc(elementRect) {
return {top, left}; return {top, left};
} }
function docImposterCreate(element) { function docImposterCreate(element, isTextarea) {
const styleProps = window.getComputedStyle(element); const styleProps = window.getComputedStyle(element);
const stylePairs = []; const stylePairs = [];
for (const key of styleProps) { for (const key of styleProps) {
@ -49,9 +49,15 @@ function docImposterCreate(element) {
imposter.style.opacity = 0; imposter.style.opacity = 0;
imposter.style.zIndex = 2147483646; imposter.style.zIndex = 2147483646;
imposter.style.margin = '0'; imposter.style.margin = '0';
if (element.nodeName === 'TEXTAREA' && styleProps.overflow === 'visible') { if (isTextarea) {
if (styleProps.overflow === 'visible') {
imposter.style.overflow = 'auto'; imposter.style.overflow = 'auto';
} }
} else {
imposter.style.overflow = 'hidden';
imposter.style.whiteSpace = 'nowrap';
imposter.style.lineHeight = styleProps.height;
}
document.body.appendChild(imposter); document.body.appendChild(imposter);
@ -79,8 +85,10 @@ function docRangeFromPoint(point) {
case 'BUTTON': case 'BUTTON':
return new TextSourceElement(element); return new TextSourceElement(element);
case 'INPUT': case 'INPUT':
imposter = docImposterCreate(element, false);
break;
case 'TEXTAREA': case 'TEXTAREA':
imposter = docImposterCreate(element); imposter = docImposterCreate(element, true);
break; break;
} }
} }