Fix regression where click event in the DOM is no longer being captured (#675)

This commit is contained in:
Red J Adaya 2024-06-08 08:41:05 +08:00 committed by GitHub
parent 29ad232ac6
commit 7888a61766
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -223,32 +223,21 @@ class ChatSidebar extends React.Component<{}, {}> {
}
);
if (this.sidebarRef.current) {
this.sidebarRef.current.addEventListener("click", this.handleSidebarClick);
this.sidebarRef.current.addEventListener("click", this.onSidebarClick);
}
document.addEventListener("click", this.handleClickOutside);
this.requestChatUpdate();
}
componentWillUnmount() {
if (this.sidebarRef.current) {
this.sidebarRef.current.removeEventListener("click", this.handleSidebarClick);
this.sidebarRef.current.removeEventListener("click", this.onSidebarClick);
}
document.removeEventListener("click", this.handleClickOutside);
GlobalModel.sidebarchatModel.resetFocus();
if (this.disposeReaction) {
this.disposeReaction();
}
}
@mobx.action.bound
handleClickOutside(e: MouseEvent) {
const sidebar = this.sidebarRef.current;
if (sidebar && !sidebar.contains(e.target as Node)) {
GlobalModel.sidebarchatModel.resetFocus();
GlobalModel.inputModel.giveFocus();
}
}
requestChatUpdate() {
const chatMessageItems = GlobalModel.inputModel.AICmdInfoChatItems.slice();
if (chatMessageItems == null || chatMessageItems.length === 0) {
@ -326,6 +315,11 @@ class ChatSidebar extends React.Component<{}, {}> {
currentRef.setRangeText("\n", currentRef.selectionStart, currentRef.selectionEnd, "end");
}
@mobx.action.bound
onBlur() {
GlobalModel.sidebarchatModel.resetFocus();
}
updatePreTagOutline(clickedPre?) {
const pres = this.chatWindowRef.current?.querySelectorAll("pre");
if (pres == null) {
@ -342,7 +336,7 @@ class ChatSidebar extends React.Component<{}, {}> {
}
@mobx.action.bound
handleSidebarClick(event) {
onSidebarClick(event) {
const target = event.target as HTMLElement;
if (
target.closest(".copy-button") ||
@ -547,6 +541,7 @@ class ChatSidebar extends React.Component<{}, {}> {
autoComplete="off"
autoCorrect="off"
className="sidebarchat-input chat-textarea"
onBlur={this.onBlur}
onFocus={this.onTextAreaFocus}
onMouseDown={this.onTextAreaMouseDown} // When the user clicks on the textarea
onChange={this.onTextAreaChange}