Skip to content

Commit

Permalink
focus chat box on chat button click in line
Browse files Browse the repository at this point in the history
  • Loading branch information
adred committed May 16, 2024
1 parent 0b3bb11 commit 5472ca3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/app/line/linecomps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class LineActions extends React.Component<{ screen: LineContainerType; line: Lin
}

@boundMethod
clickChat() {
clickChat(e: any) {
e.stopPropagation();
const { line, screen } = this.props;
const termWrap = screen.getTermWrap(line.lineid);
const cmd = screen.getCmd(line);
Expand All @@ -125,6 +126,7 @@ class LineActions extends React.Component<{ screen: LineContainerType; line: Lin
termWrap?.getOutput(false),
cmdShouldMarkError(cmd)
);
GlobalModel.sidebarchatModel.setFocus("input", true);
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/app/sidebar/aichat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ class ChatSidebar extends React.Component<{}, {}> {
mobx.makeObservable(this);
}

componentDidUpdate() {
if (GlobalModel.sidebarchatModel.getFocus("input")) {
this.textAreaRef.current.focus();
}
}

componentDidMount() {
GlobalModel.sidebarchatModel.setFocus("input", true);
if (this.sidebarRef.current) {
Expand Down Expand Up @@ -391,7 +397,6 @@ class ChatSidebar extends React.Component<{}, {}> {
const renderAIChatKeybindings = GlobalModel.sidebarchatModel.getFocus();
const cmdAndOutput = GlobalModel.sidebarchatModel.getCmdAndOutput();
const value = this.formChatMessage(cmdAndOutput);
console.log("cmdAndOutput", cmdAndOutput);
return (
<div ref={this.sidebarRef} className="sidebarchat">
<If condition={renderAIChatKeybindings}>
Expand Down
2 changes: 0 additions & 2 deletions src/models/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ class InputModel {
// nothing to do here
break;
}

GlobalModel.sidebarchatModel.resetFocus();
}

@mobx.action
Expand Down
11 changes: 8 additions & 3 deletions src/models/sidebarchat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ class SidebarChatModel {
this.sidebarChatFocus[section] = focus;
}

getFocus(section?: "input" | "block"): boolean {
getFocus(section?: "input" | "block"): string | null {
if (section == null) {
return this.sidebarChatFocus.input || this.sidebarChatFocus.block;
if (this.sidebarChatFocus.input) {
return "input";
} else if (this.sidebarChatFocus.block) {
return "block";
}
return null;
}
return this.sidebarChatFocus[section];
return this.sidebarChatFocus[section] ? section : null;
}

resetFocus(): void {
Expand Down

0 comments on commit 5472ca3

Please sign in to comment.