MCPcopy Index your code
hub / github.com/ChatGPTNextWeb/NextChat / autoGrowTextArea

Function autoGrowTextArea

app/utils.ts:197–218  ·  view source on GitHub ↗
(dom: HTMLTextAreaElement)

Source from the content-addressed store, hash-verified

195}
196
197export function autoGrowTextArea(dom: HTMLTextAreaElement) {
198 const measureDom = getOrCreateMeasureDom("__measure");
199 const singleLineDom = getOrCreateMeasureDom("__single_measure", (dom) => {
200 dom.innerText = "TEXT_FOR_MEASURE";
201 });
202
203 const width = getDomContentWidth(dom);
204 measureDom.style.width = width + "px";
205 measureDom.innerText = dom.value !== "" ? dom.value : "1";
206 measureDom.style.fontSize = dom.style.fontSize;
207 measureDom.style.fontFamily = dom.style.fontFamily;
208 const endWithEmptyLine = dom.value.endsWith("\n");
209 const height = parseFloat(window.getComputedStyle(measureDom).height);
210 const singleLineHeight = parseFloat(
211 window.getComputedStyle(singleLineDom).height,
212 );
213
214 const rows =
215 Math.round(height / singleLineHeight) + (endWithEmptyLine ? 1 : 0);
216
217 return rows;
218}
219
220export function getCSSVar(varName: string) {
221 return getComputedStyle(document.body).getPropertyValue(varName).trim();

Callers 1

_ChatFunction · 0.90

Calls 2

getOrCreateMeasureDomFunction · 0.85
getDomContentWidthFunction · 0.85

Tested by

no test coverage detected