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
6 changes: 6 additions & 0 deletions src/vs/base/browser/ui/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ export class Dialog extends Disposable {
}
}

if (focusableElements.length === 0) {
// Nothing to move focus to, so it stays inside the dialog
EventHelper.stop(e, true);
return;
}

// Focus next element (with wrapping)
if (evt.equals(KeyCode.Tab) || evt.equals(KeyCode.RightArrow)) {
const newFocusedIndex = (focusedIndex + 1) % focusableElements.length;
Expand Down
29 changes: 29 additions & 0 deletions src/vs/base/test/browser/ui/dialog/dialog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,33 @@ suite('Dialog', () => {
dialog.dispose();
await result;
});

test('keeps Tab inside a dialog with nothing to focus', async () => {
const container = append(document.body, $('.test-dialog-container'));
disposables.add(toDisposable(() => container.remove()));
const dialog = disposables.add(new Dialog(container, 'Message', [], {
disableDefaultAction: true,
buttonStyles: unthemedButtonStyles,
checkboxStyles: unthemedCheckboxStyles,
inputBoxStyles: unthemedInboxStyles,
dialogStyles: unthemedDialogStyles,
}));
const result = dialog.show();

const targetWindow = getWindow(container);
const focused = targetWindow.document.activeElement;
const event = new targetWindow.KeyboardEvent('keydown', { key: 'Tab', keyCode: 9, bubbles: true, cancelable: true });
focused?.dispatchEvent(event);

assert.deepStrictEqual({
activeElement: targetWindow.document.activeElement,
defaultPrevented: event.defaultPrevented,
}, {
activeElement: focused,
defaultPrevented: true,
});

dialog.dispose();
await result;
});
});
26 changes: 18 additions & 8 deletions src/vs/platform/agentHost/common/computerUse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,30 @@ export type ComputerUsePermissionState = typeof computerUsePermissionStates[numb
* - `needsPermissions`: the plugin waits for the user to choose an action.
* - `working`: an action was sent and the plugin has not reported its outcome yet.
* - `ready`: the plugin verified both permissions and resumed the operation that was waiting.
* - `ended`: the setup closed without readiness; see {@link IComputerUseSetupV1.error}.
* - `ended`: the setup closed without readiness, e.g. because the user declined or the waiting tool call or turn stopped.
*/
export const computerUseSetupStates = ['needsPermissions', 'working', 'ready', 'ended'] as const;
export type ComputerUseSetupState = typeof computerUseSetupStates[number];

/**
* - `request`: show the native macOS permission prompt for a permission.
* - `openSettings`: open the permission's pane in System Settings.
* - `allow`: get a permission turned on. The first time the host asks for the permission in this Agent Host process, it
* shows the native macOS prompt, which macOS shows only once per app. After that it opens the permission's pane in
* System Settings. The plugin offers the pane only after a native request in its current loop, so in a new loop the
* host first sends a native request that macOS keeps silent, and opens the pane on the plugin's next prompt.
* - `recheck`: restart Copilot Computer Use's helper, which some grants need to take effect, and verify again.
*/
export const computerUseActions = ['request', 'openSettings', 'recheck'] as const;
export const computerUseActions = ['allow', 'recheck'] as const;
export type ComputerUseAction = typeof computerUseActions[number];

/** Actions that must carry {@link IComputerUseRequest.permission}. */
export const computerUsePermissionActions: readonly ComputerUseAction[] = ['request', 'openSettings'];
export const computerUsePermissionActions: readonly ComputerUseAction[] = ['allow'];

export interface IComputerUsePermissionStatusV1 {
readonly permission: ComputerUsePermission;
readonly state: ComputerUsePermissionState;
}

/** An action the plugin accepts for a setup now. */
/** An action a setup accepts now. */
export interface IComputerUseSetupActionV1 {
readonly action: ComputerUseAction;
/** Present exactly for {@link computerUsePermissionActions}. */
Expand All @@ -114,12 +116,20 @@ export interface IComputerUseSetupV1 {
readonly state: ComputerUseSetupState;
/** Increments every time the plugin reports the permissions again; requests must name the current round. */
readonly round: number;
/** What the plugin accepts now. Empty unless {@link state} is `needsPermissions`. */
/** `allow` for each permission the plugin found missing, and `recheck`. Empty unless {@link state} is `needsPermissions`. */
readonly actions: readonly IComputerUseSetupActionV1[];
/**
* Only `stillNotGranted`: a check the user asked for changed nothing. Clients announce it to screen readers. Ended
* setups carry none.
*/
readonly error?: IComputerUseErrorV1;
}

/** The action in flight. At most one runs at a time across all setups, because they share one helper and one set of native prompts. */
/**
* The action in flight: `allow` with its permission while the host has macOS ask for it or opens its System Settings
* pane, `recheck` while the helper verifies again. At most one runs at a time across all setups, because they share one
* helper and one set of native prompts.
*/
export interface IComputerUseOperationV1 {
readonly setupId: string;
readonly action: ComputerUseAction;
Expand Down
Loading
Loading