Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/backends/idb-backend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2850,6 +2850,16 @@ describe('IdbBackend keys and buttons', () => {
);
});

it('only clears the field for an empty string', async () => {
await backend.typeText('');

// `idb ui text ""` exits 1, so it is skipped like the ADB backend does.
expect(idbCalls()).toStrictEqual([
['ui', 'key', '4', '--command', '--udid', udid],
['ui', 'key', '42', '--udid', udid],
]);
});

it('presses Return to dismiss a visible keyboard', async () => {
mockExecStrict.mockImplementation(async (_cmd, args) =>
args?.[1] === 'describe-all' ? hierarchyWith(['Keyboard']) : '',
Expand Down
7 changes: 7 additions & 0 deletions src/backends/idb-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ export class IdbBackend implements DeviceBackend {
* strict execution so a failed clear rejects instead of appending to the
* old value. On an empty field the two keys do nothing.
*
* Empty text stops after the clear: `idb ui text ""` exits 1 with
* "Request was not sent", and the field is already empty. This matches the
* ADB backend.
*
* @param text - The text to type.
*/
async typeText(text: string): Promise<void> {
Expand All @@ -752,6 +756,9 @@ export class IdbBackend implements DeviceBackend {
'--udid',
this.#udid,
]);
if (text.length === 0) {
return;
}
await this.#execStrict(this.#idbPath, [
'ui',
'text',
Expand Down
4 changes: 2 additions & 2 deletions src/tools/type-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export function registerTypeTool(
description:
'Type text into the currently focused input field. ' +
'Tap an input element first to focus it, then call this. ' +
'The field is cleared before typing on all backends. On Android ' +
'(adb), an empty string clears the field.',
'The field is cleared before typing on all backends. An empty ' +
'string only clears the field.',
inputSchema: {
text: z.string().describe('Text to type'),
},
Expand Down
Loading