Skip to content

Commit 256b87e

Browse files
committed
fix(desktop): retain snapshot metadata when text is unchanged
1 parent 1bbfe8a commit 256b87e

2 files changed

Lines changed: 46 additions & 7 deletions

File tree

‎apps/desktop/src/snapShot/DesktopSnapShot.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,6 +2780,43 @@ it("keeps a truncated element tree when the flat text read fails", async () => {
27802780
);
27812781
});
27822782

2783+
it("keeps a truncated tree when flat text would not recover any text", async () => {
2784+
const bounds = { x: 0, y: 0, width: 800, height: 600 };
2785+
accessibilityByPidMock.mockReset().mockResolvedValue({
2786+
children: async () => [
2787+
{
2788+
role: "window",
2789+
name: "Editor",
2790+
bounds,
2791+
tree: async () => ({ name: "Editor", children: [{ name: "Help", children: [] }] }),
2792+
children: async () => [
2793+
{
2794+
role: "button",
2795+
name: "Help",
2796+
description: "Help text ".repeat(250),
2797+
bounds,
2798+
children: async () => [],
2799+
},
2800+
],
2801+
},
2802+
],
2803+
});
2804+
2805+
const result = await readAccessibleWindowContext(
2806+
{ title: "Editor", bounds, owner: { processId: 123 } },
2807+
"darwin",
2808+
"Editor",
2809+
);
2810+
assert.equal(result?.accessibility?.format, "element-tree");
2811+
assert.isTrue(result?.accessibility?.truncated);
2812+
assert.include(
2813+
result?.accessibility?.format === "element-tree"
2814+
? result.accessibility.root.children[0]?.description
2815+
: undefined,
2816+
"Help text",
2817+
);
2818+
});
2819+
27832820
it("times out after three seconds without overlapping the outstanding accessibility read", async () => {
27842821
vi.useFakeTimers();
27852822
accessibilityByPidMock.mockReset();

‎apps/desktop/src/snapShot/SnapShotAccessibility.ts‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,20 @@ function accessibilityReadSnapshot(
5757
descendantLocationsReliable: progress.richLocationsReliable,
5858
})
5959
: undefined;
60-
const accessibleText =
61-
progress.accessibleText ??
62-
(richTree
63-
? accessibleWindowText(richTree.root, SNAP_SHOT_ACCESSIBLE_TEXT_MAX_CHARS)
64-
: undefined);
60+
const richText = richTree
61+
? accessibleWindowText(richTree.root, SNAP_SHOT_ACCESSIBLE_TEXT_MAX_CHARS)
62+
: undefined;
63+
const accessibleText = progress.accessibleText ?? richText;
64+
const richTruncated = progress.richTruncated || richTree?.truncated === true;
6565
const accessibility: SnapShotAccessibility | undefined =
66-
progress.richComplete && richTree && !progress.richTruncated && !richTree.truncated
66+
progress.richComplete &&
67+
richTree &&
68+
(!richTruncated || !progress.accessibleText || progress.accessibleText === richText)
6769
? {
6870
format: "element-tree",
6971
coordinateSpace: "captured-image",
7072
imageSize,
71-
truncated: false,
73+
truncated: richTruncated,
7274
root: richTree.root,
7375
}
7476
: progress.flatComplete && progress.accessibleText

0 commit comments

Comments
 (0)