Просмотр исходного кода

fix(tui): stop caret redraws while idle

Ma 7 месяцев назад
Родитель
Сommit
b8ac5b2cee

+ 2 - 11
packages/cli/src/__tests__/tui-composer-caret.test.ts

@@ -13,29 +13,20 @@ describe("tui composer caret", () => {
     });
   });
 
-  it("blinks briefly after typing and then settles", () => {
+  it("keeps the typed composer caret visible without animation", () => {
     expect(resolveComposerCaretState({
       inputValue: "continue",
       isSubmitting: false,
       blinkTick: 0,
     })).toEqual({
       visible: true,
-      shouldAnimate: true,
+      shouldAnimate: false,
     });
 
     expect(resolveComposerCaretState({
       inputValue: "continue",
       isSubmitting: false,
       blinkTick: 1,
-    })).toEqual({
-      visible: false,
-      shouldAnimate: true,
-    });
-
-    expect(resolveComposerCaretState({
-      inputValue: "continue",
-      isSubmitting: false,
-      blinkTick: 2,
     })).toEqual({
       visible: true,
       shouldAnimate: false,

+ 2 - 16
packages/cli/src/tui/composer-caret.ts

@@ -15,22 +15,8 @@ export function resolveComposerCaretState(params: {
     };
   }
 
-  if (!params.inputValue) {
-    return {
-      visible: true,
-      shouldAnimate: false,
-    };
-  }
-
-  if (params.blinkTick >= 2) {
-    return {
-      visible: true,
-      shouldAnimate: false,
-    };
-  }
-
   return {
-    visible: params.blinkTick % 2 === 0,
-    shouldAnimate: true,
+    visible: true,
+    shouldAnimate: false,
   };
 }

+ 1 - 17
packages/cli/src/tui/dashboard.tsx

@@ -165,7 +165,6 @@ export function InkTuiApp(props: InkTuiAppProps): React.JSX.Element {
   const [activityIntent, setActivityIntent] = useState<InteractionIntentType | "unknown">("unknown");
   const [activityFrameIndex, setActivityFrameIndex] = useState(0);
   const [chatDepth, setChatDepth] = useState<ChatDepth>("normal");
-  const [composerCaretTick, setComposerCaretTick] = useState(0);
   const assistantDraftTimestampRef = useRef<number | null>(null);
   const submitLockRef = useRef(false);
   const slashSuggestions = getSlashSuggestions(inputValue, SLASH_COMMANDS);
@@ -175,7 +174,7 @@ export function InkTuiApp(props: InkTuiAppProps): React.JSX.Element {
   const composerCaret = resolveComposerCaretState({
     inputValue,
     isSubmitting,
-    blinkTick: composerCaretTick,
+    blinkTick: 0,
   });
 
   useEffect(() => {
@@ -190,21 +189,6 @@ export function InkTuiApp(props: InkTuiAppProps): React.JSX.Element {
     return () => clearInterval(timer);
   }, [activity.frames.length, activity.intervalMs, isSubmitting]);
 
-  useEffect(() => {
-    setComposerCaretTick(0);
-  }, [inputValue, isSubmitting]);
-
-  useEffect(() => {
-    if (!composerCaret.shouldAnimate) {
-      return;
-    }
-
-    const timer = setTimeout(() => {
-      setComposerCaretTick((current) => current + 1);
-    }, 900);
-    return () => clearTimeout(timer);
-  }, [composerCaret.shouldAnimate, composerCaretTick]);
-
   if (props.chatStreamBridge) {
     props.chatStreamBridge.getChatRequestOptions = () => ({
       temperature: chatDepthProfile.temperature,