mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
Fix issue where WaveAI text area would resize on launch (#1397)
This commit is contained in:
parent
8ec3c3f330
commit
cb50023d79
@ -572,24 +572,33 @@ const ChatInput = forwardRef<HTMLTextAreaElement, ChatInputProps>(
|
|||||||
model.textAreaRef = textAreaRef;
|
model.textAreaRef = textAreaRef;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const adjustTextAreaHeight = () => {
|
const adjustTextAreaHeight = useCallback(
|
||||||
|
(value: string) => {
|
||||||
if (textAreaRef.current == null) {
|
if (textAreaRef.current == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust the height of the textarea to fit the text
|
// Adjust the height of the textarea to fit the text
|
||||||
const textAreaMaxLines = 100;
|
const textAreaMaxLines = 5;
|
||||||
const textAreaLineHeight = termFontSize * 1.5;
|
const textAreaLineHeight = termFontSize * 1.5;
|
||||||
const textAreaMinHeight = textAreaLineHeight;
|
const textAreaMinHeight = textAreaLineHeight;
|
||||||
const textAreaMaxHeight = textAreaLineHeight * textAreaMaxLines;
|
const textAreaMaxHeight = textAreaLineHeight * textAreaMaxLines;
|
||||||
|
|
||||||
textAreaRef.current.style.height = "1px";
|
if (value === "") {
|
||||||
|
textAreaRef.current.style.height = `${textAreaLineHeight}px`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
textAreaRef.current.style.height = `${textAreaLineHeight}px`;
|
||||||
const scrollHeight = textAreaRef.current.scrollHeight;
|
const scrollHeight = textAreaRef.current.scrollHeight;
|
||||||
const newHeight = Math.min(Math.max(scrollHeight, textAreaMinHeight), textAreaMaxHeight);
|
const newHeight = Math.min(Math.max(scrollHeight, textAreaMinHeight), textAreaMaxHeight);
|
||||||
textAreaRef.current.style.height = newHeight + "px";
|
textAreaRef.current.style.height = newHeight + "px";
|
||||||
};
|
},
|
||||||
|
[termFontSize]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
adjustTextAreaHeight();
|
adjustTextAreaHeight(value);
|
||||||
}, [value]);
|
}, [value]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user