Browse Source

fix(drive): serialize unfocused UI state (#42360)

Kit Langton 3 ngày trước cách đây
mục cha
commit
c7de57ee0e

+ 2 - 1
packages/simulation/src/frontend/actions.ts

@@ -115,9 +115,10 @@ export function elements(renderer: CliRenderer): Element[] {
 }
 
 export function state(harness: Harness) {
+  const renderable = harness.renderer.currentFocusedRenderable?.num
   return {
     focused: {
-      renderable: harness.renderer.currentFocusedRenderable?.num,
+      ...(renderable === undefined ? {} : { renderable }),
       editor: Boolean(harness.renderer.currentFocusedEditor),
     },
     elements: elements(harness.renderer),

+ 12 - 0
packages/simulation/test/actions.test.ts

@@ -14,6 +14,18 @@ test("matches literal screen text", () => {
   expect(matches(harness, "opencode")).toBe(false)
 })
 
+test("omits an absent focused renderable from state", () => {
+  const harness = {
+    renderer: {
+      root: { getChildren: () => [] },
+      currentFocusedRenderable: undefined,
+      currentFocusedEditor: undefined,
+    },
+  } as unknown as Harness
+
+  expect(state(harness)).toEqual({ focused: { editor: false }, elements: [] })
+})
+
 test("normalizes named keys for OpenTUI", async () => {
   const pressed: Array<readonly [string, object | undefined]> = []
   const harness = {