Skip to content

Commit

Permalink
make sure chatbox height adjusts to its content
Browse files Browse the repository at this point in the history
  • Loading branch information
adred committed May 16, 2024
1 parent f4807c3 commit 1eaecb0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/app/line/linecomps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class LineActions extends React.Component<{ screen: LineContainerType; line: Lin
const termWrap = screen.getTermWrap(line.lineid);
const cmd = screen.getCmd(line);
if (termWrap && cmd) {
// console.log("screen.getUsedRows()", screen.getCmd(line)?.getUsedRows());
GlobalModel.sidebarchatModel.setCmdAndOutput(
screen.getCmd(line)?.getCmdStr(),
termWrap?.getOutput(false),
Expand Down
7 changes: 5 additions & 2 deletions src/app/sidebar/aichat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ class ChatSidebar extends React.Component<{}, {}> {
if (GlobalModel.sidebarchatModel.getFocus("input")) {
this.textAreaRef.current.focus();
}

if (GlobalModel.sidebarchatModel.hasCmdAndOutput()) {
const newCmdAndOutput = GlobalModel.sidebarchatModel.getCmdAndOutput();
const newValue = this.formChatMessage(newCmdAndOutput);
if (newValue !== this.value.get()) {
this.value.set(newValue);
}
}
this.adjustTextAreaHeight();
}

componentDidMount() {
Expand Down Expand Up @@ -212,13 +212,16 @@ class ChatSidebar extends React.Component<{}, {}> {
onTextAreaChange(e) {
const newValue = e.target.value;
this.value.set(newValue);
this.adjustTextAreaHeight();
}

adjustTextAreaHeight() {
if (this.textAreaRef.current == null) {
return;
}

// Adjust the height of the textarea to fit the text
const textAreaMaxLines = 4;
const textAreaMaxLines = 100;
const textAreaLineHeight = this.termFontSize * 1.5;
const textAreaMinHeight = textAreaLineHeight;
const textAreaMaxHeight = textAreaLineHeight * textAreaMaxLines;
Expand Down

0 comments on commit 1eaecb0

Please sign in to comment.