mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48:23 +01:00
auxview focus + keybindings (#575)
* first draft of figuring out auxviews and focus * added more focus logic * fixed aichat focus issue * fixed artifacts * removed command * addressed review comments
This commit is contained in:
parent
c683d10008
commit
64244626a1
@ -9,6 +9,7 @@ import { boundMethod } from "autobind-decorator";
|
|||||||
import { If, For } from "tsx-control-statements/components";
|
import { If, For } from "tsx-control-statements/components";
|
||||||
import { Markdown } from "@/elements";
|
import { Markdown } from "@/elements";
|
||||||
import { AuxiliaryCmdView } from "./auxview";
|
import { AuxiliaryCmdView } from "./auxview";
|
||||||
|
import * as appconst from "@/app/appconst";
|
||||||
|
|
||||||
import "./aichat.less";
|
import "./aichat.less";
|
||||||
|
|
||||||
@ -56,18 +57,13 @@ class AIChat extends React.Component<{}, {}> {
|
|||||||
chatListKeyCount: number = 0;
|
chatListKeyCount: number = 0;
|
||||||
chatWindowScrollRef: React.RefObject<HTMLDivElement>;
|
chatWindowScrollRef: React.RefObject<HTMLDivElement>;
|
||||||
textAreaRef: React.RefObject<HTMLTextAreaElement>;
|
textAreaRef: React.RefObject<HTMLTextAreaElement>;
|
||||||
isFocused: OV<boolean>;
|
|
||||||
termFontSize: number = 14;
|
termFontSize: number = 14;
|
||||||
|
|
||||||
constructor(props: any) {
|
constructor(props: any) {
|
||||||
super(props);
|
super(props);
|
||||||
this.chatWindowScrollRef = React.createRef();
|
this.chatWindowScrollRef = React.createRef();
|
||||||
this.textAreaRef = React.createRef();
|
this.textAreaRef = React.createRef();
|
||||||
this.isFocused = mobx.observable.box(false, {
|
|
||||||
name: "aichat-isfocused",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const inputModel = GlobalModel.inputModel;
|
const inputModel = GlobalModel.inputModel;
|
||||||
if (this.chatWindowScrollRef?.current != null) {
|
if (this.chatWindowScrollRef?.current != null) {
|
||||||
@ -109,13 +105,13 @@ class AIChat extends React.Component<{}, {}> {
|
|||||||
|
|
||||||
onTextAreaFocused(e: any) {
|
onTextAreaFocused(e: any) {
|
||||||
mobx.action(() => {
|
mobx.action(() => {
|
||||||
this.isFocused.set(true);
|
GlobalModel.inputModel.setAuxViewFocus(true);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
onTextAreaBlur(e: any) {
|
onTextAreaBlur(e: any) {
|
||||||
mobx.action(() => {
|
mobx.action(() => {
|
||||||
this.isFocused.set(false);
|
GlobalModel.inputModel.setAuxViewFocus(false);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,17 +233,7 @@ class AIChat extends React.Component<{}, {}> {
|
|||||||
render() {
|
render() {
|
||||||
const chatMessageItems = GlobalModel.inputModel.AICmdInfoChatItems.slice();
|
const chatMessageItems = GlobalModel.inputModel.AICmdInfoChatItems.slice();
|
||||||
const chitem: OpenAICmdInfoChatMessageType = null;
|
const chitem: OpenAICmdInfoChatMessageType = null;
|
||||||
const renderKeybindings = mobx
|
const renderKeybindings = GlobalModel.inputModel.shouldRenderAuxViewKeybindings(appconst.InputAuxView_AIChat);
|
||||||
.computed(() => {
|
|
||||||
return (
|
|
||||||
this.isFocused.get() ||
|
|
||||||
GlobalModel.inputModel.hasFocus() ||
|
|
||||||
(GlobalModel.getActiveScreen().getFocusType() == "input" &&
|
|
||||||
GlobalModel.activeMainView.get() == "session")
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.get();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuxiliaryCmdView
|
<AuxiliaryCmdView
|
||||||
title="Wave AI"
|
title="Wave AI"
|
||||||
|
@ -174,7 +174,7 @@ class HistoryInfo extends React.Component<{}, {}> {
|
|||||||
handleItemClick(hitem: HistoryItem) {
|
handleItemClick(hitem: HistoryItem) {
|
||||||
const inputModel = GlobalModel.inputModel;
|
const inputModel = GlobalModel.inputModel;
|
||||||
const selItem = inputModel.getHistorySelectedItem();
|
const selItem = inputModel.getHistorySelectedItem();
|
||||||
inputModel.setAuxViewFocus(false);
|
inputModel.setAuxViewFocus(!inputModel.getAuxViewFocus());
|
||||||
if (this.lastClickHNum == hitem.historynum && selItem != null && selItem.historynum == hitem.historynum) {
|
if (this.lastClickHNum == hitem.historynum && selItem != null && selItem.historynum == hitem.historynum) {
|
||||||
inputModel.grabSelectedHistoryItem();
|
inputModel.grabSelectedHistoryItem();
|
||||||
return;
|
return;
|
||||||
|
@ -602,18 +602,21 @@ class TextAreaInput extends React.Component<{ screen: Screen; onHeightChange: ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const isHistoryFocused = auxViewFocused && inputModel.getActiveAuxView() == appconst.InputAuxView_History;
|
|
||||||
|
const renderCmdInputKeybindings = inputModel.shouldRenderAuxViewKeybindings(null);
|
||||||
|
const renderHistoryKeybindings = inputModel.shouldRenderAuxViewKeybindings(appconst.InputAuxView_History);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="textareainput-div control is-expanded"
|
className="textareainput-div control is-expanded"
|
||||||
ref={this.controlRef}
|
ref={this.controlRef}
|
||||||
style={{ height: computedOuterHeight }}
|
style={{ height: computedOuterHeight }}
|
||||||
>
|
>
|
||||||
<If condition={!auxViewFocused}>
|
<If condition={renderCmdInputKeybindings}>
|
||||||
<CmdInputKeybindings inputObject={this} />
|
<CmdInputKeybindings inputObject={this}></CmdInputKeybindings>
|
||||||
</If>
|
</If>
|
||||||
<If condition={isHistoryFocused}>
|
<If condition={renderHistoryKeybindings}>
|
||||||
<HistoryKeybindings />
|
<HistoryKeybindings inputObject={this}></HistoryKeybindings>
|
||||||
</If>
|
</If>
|
||||||
|
|
||||||
<If condition={!util.isBlank(shellType)}>
|
<If condition={!util.isBlank(shellType)}>
|
||||||
|
@ -7,7 +7,7 @@ import { boundMethod } from "autobind-decorator";
|
|||||||
import { isBlank } from "@/util/util";
|
import { isBlank } from "@/util/util";
|
||||||
import * as appconst from "@/app/appconst";
|
import * as appconst from "@/app/appconst";
|
||||||
import type { Model } from "./model";
|
import type { Model } from "./model";
|
||||||
import { GlobalCommandRunner } from "./global";
|
import { GlobalCommandRunner, GlobalModel } from "./global";
|
||||||
import { app } from "electron";
|
import { app } from "electron";
|
||||||
|
|
||||||
function getDefaultHistoryQueryOpts(): HistoryQueryOpts {
|
function getDefaultHistoryQueryOpts(): HistoryQueryOpts {
|
||||||
@ -500,6 +500,29 @@ class InputModel {
|
|||||||
this.giveFocus();
|
this.giveFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shouldRenderAuxViewKeybindings(view: InputAuxViewType): boolean {
|
||||||
|
return mobx
|
||||||
|
.computed(() => {
|
||||||
|
if (view != null && this.getActiveAuxView() != view) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (view == null && this.hasFocus() && !this.getAuxViewFocus()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (view != null && this.getAuxViewFocus()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
GlobalModel.getActiveScreen().getFocusType() == "input" &&
|
||||||
|
GlobalModel.activeMainView.get() == "session"
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
.get();
|
||||||
|
}
|
||||||
|
|
||||||
setHistoryIndex(hidx: number, force?: boolean): void {
|
setHistoryIndex(hidx: number, force?: boolean): void {
|
||||||
if (hidx < 0) {
|
if (hidx < 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -759,11 +759,11 @@ class Model {
|
|||||||
this.activeMainView.set("session");
|
this.activeMainView.set("session");
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// allows for the session view to load
|
// allows for the session view to load
|
||||||
this.inputModel.giveFocus();
|
this.inputModel.setAuxViewFocus(false);
|
||||||
}, 100);
|
}, 100);
|
||||||
})();
|
})();
|
||||||
} else {
|
} else {
|
||||||
this.inputModel.giveFocus();
|
this.inputModel.setAuxViewFocus(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user