From c93b6e3d343e011f9dec7af8ddf2693cc761cae3 Mon Sep 17 00:00:00 2001 From: Red Adaya Date: Wed, 8 May 2024 06:39:51 +0800 Subject: [PATCH] save work --- src/app/common/elements/markdown.tsx | 1 + src/app/sidebar/aichat.tsx | 24 ++++++++----- src/models/aichat.ts | 1 - src/models/input.ts | 52 ++++++++++++++++++++++++++-- 4 files changed, 66 insertions(+), 12 deletions(-) diff --git a/src/app/common/elements/markdown.tsx b/src/app/common/elements/markdown.tsx index a88386e44..a68afebc5 100644 --- a/src/app/common/elements/markdown.tsx +++ b/src/app/common/elements/markdown.tsx @@ -50,6 +50,7 @@ class CodeBlockMarkdown extends React.Component< } render() { + console.log("this.blockIndex", this.blockIndex); let selected = this.blockIndex == this.props.codeSelectSelectedIndex; return (
diff --git a/src/app/sidebar/aichat.tsx b/src/app/sidebar/aichat.tsx
index c8d847fd8..19173158e 100644
--- a/src/app/sidebar/aichat.tsx
+++ b/src/app/sidebar/aichat.tsx
@@ -63,11 +63,13 @@ class ChatContent extends React.Component<{ chatWindowRef }, {}> {
     componentDidUpdate() {
         this.chatListKeyCount = 0;
         if (this.containerRef?.current && this.osInstance) {
-            const { viewport } = this.osInstance.elements();
-            viewport.scrollTo({
-                behavior: "auto",
-                top: this.props.chatWindowRef.current.scrollHeight,
-            });
+            const { viewport, scrollOffsetElement } = this.osInstance.elements();
+            const { scrollTop } = scrollOffsetElement;
+            console.log("this.props.chatWindowRef.current.scrollTop", scrollTop);
+            // viewport.scrollTo({
+            //     behavior: "auto",
+            //     top: this.props.chatWindowRef.current.scrollHeight,
+            // });
         }
     }
 
@@ -80,12 +82,14 @@ class ChatContent extends React.Component<{ chatWindowRef }, {}> {
 
     @boundMethod
     onScrollbarInitialized(instance) {
+        console.log("got here");
+        GlobalModel.inputModel.setChatOsInstance(instance);
         this.osInstance = instance;
         const { viewport } = instance.elements();
-        viewport.scrollTo({
-            behavior: "auto",
-            top: this.props.chatWindowRef.current.scrollHeight,
-        });
+        // viewport.scrollTo({
+        //     behavior: "auto",
+        //     top: this.props.chatWindowRef.current.scrollHeight,
+        // });
     }
 
     renderError(err: string): any {
@@ -309,6 +313,8 @@ class AIChat extends React.Component<{}, {}> {
             appconst.InputAuxView_AIChat
         );
         console.log("renderAIChatKeybindings=====", renderAIChatKeybindings);
+        console.log("codeSelectBlockRefArray", GlobalModel.inputModel.codeSelectBlockRefArray);
+
         return (
             
diff --git a/src/models/aichat.ts b/src/models/aichat.ts index 3aeebd12f..2e1e2a726 100644 --- a/src/models/aichat.ts +++ b/src/models/aichat.ts @@ -4,7 +4,6 @@ import type React from "react"; import * as mobx from "mobx"; import { Model } from "./model"; -import { GlobalCommandRunner } from "./global"; class AIChatModel { globalModel: Model; diff --git a/src/models/input.ts b/src/models/input.ts index 2a239edad..1480921bd 100644 --- a/src/models/input.ts +++ b/src/models/input.ts @@ -7,6 +7,8 @@ import { isBlank } from "@/util/util"; import * as appconst from "@/app/appconst"; import type { Model } from "./model"; import { GlobalCommandRunner, GlobalModel } from "./global"; +import type { OverlayScrollbars } from "overlayscrollbars"; +import { boundMethod } from "autobind-decorator"; function getDefaultHistoryQueryOpts(): HistoryQueryOpts { return { @@ -28,6 +30,7 @@ class InputModel { cmdInputHeight: OV = mobx.observable.box(0); aiChatTextAreaRef: React.RefObject; aiChatWindowRef: React.RefObject; + chatOsInstance: OverlayScrollbars; codeSelectBlockRefArray: Array>; codeSelectSelectedIndex: OV = mobx.observable.box(-1); codeSelectUuid: string; @@ -547,6 +550,11 @@ class InputModel { this.aiChatWindowRef = chatWindowRef; } + setChatOsInstance(osInstance: OverlayScrollbars) { + console.log("triggered***********"); + this.chatOsInstance = osInstance; + } + setAIChatFocus() { if (this.aiChatTextAreaRef?.current != null) { this.aiChatTextAreaRef.current.focus(); @@ -565,11 +573,14 @@ class InputModel { } } + @mobx.action addCodeBlockToCodeSelect(blockRef: React.RefObject, uuid: string): number { let rtn = -1; + // Why is codeSelectBlockRefArray being reset here? This causes a bug where multiple code blocks are highlighted + // because multiple code blocks have the same index. if (uuid != this.codeSelectUuid) { - this.codeSelectUuid = uuid; - this.codeSelectBlockRefArray = []; + // this.codeSelectUuid = uuid; + // this.codeSelectBlockRefArray = []; } rtn = this.codeSelectBlockRefArray.length; this.codeSelectBlockRefArray.push(blockRef); @@ -578,6 +589,10 @@ class InputModel { @mobx.action setCodeSelectSelectedCodeBlock(blockIndex: number) { + // const { viewport, scrollOffsetElement } = this.chatOsInstance.elements(); + // const { scrollTop } = scrollOffsetElement; + // console.log("setCodeSelectSelectedCodeBlock", scrollTop); + // console.log("clientHeight", this.aiChatWindowRef.current.clientHeight); if (blockIndex >= 0 && blockIndex < this.codeSelectBlockRefArray.length) { this.codeSelectSelectedIndex.set(blockIndex); const currentRef = this.codeSelectBlockRefArray[blockIndex].current; @@ -597,6 +612,39 @@ class InputModel { this.setAuxViewFocus(true); } + // @mobx.action + // setCodeSelectSelectedCodeBlock(blockIndex: number) { + // const { viewport, scrollOffsetElement } = this.chatOsInstance.elements(); + // const { scrollTop } = scrollOffsetElement; + // console.log("setCodeSelectSelectedCodeBlock", scrollTop); + // console.log("clientHeight", this.aiChatWindowRef.current.clientHeight); + // if (blockIndex >= 0 && blockIndex < this.codeSelectBlockRefArray.length) { + // this.codeSelectSelectedIndex.set(blockIndex); + // const currentRef = this.codeSelectBlockRefArray[blockIndex].current; + // if (currentRef != null && this.aiChatWindowRef?.current != null) { + // const chatWindowTop = scrollTop; + // const chatWindowBottom = chatWindowTop + this.aiChatWindowRef.current.clientHeight - 100; + // const elemTop = currentRef.offsetTop; + // let elemBottom = elemTop - currentRef.offsetHeight; + // const elementIsInView = elemBottom < chatWindowBottom && elemTop > chatWindowTop; + // if (!elementIsInView) { + // console.log( + // "elemBottom - this.aiChatWindowRef.current.clientHeight / 3", + // elemBottom - this.aiChatWindowRef.current.clientHeight / 3 + // ); + // viewport.scrollTo({ + // behavior: "auto", + // top: elemBottom - this.aiChatWindowRef.current.clientHeight / 3, + // }); + // // this.aiChatWindowRef.current.scrollTop = elemBottom - this.aiChatWindowRef.current.clientHeight / 3; + // } + // } + // } + // this.codeSelectBlockRefArray = []; + // this.setActiveAuxView(appconst.InputAuxView_AIChat); + // this.setAuxViewFocus(true); + // } + @mobx.action codeSelectSelectNextNewestCodeBlock() { // oldest code block = index 0 in array