Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New File dialog doesn't accept Enter for default #14146

Merged
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
9 changes: 4 additions & 5 deletions examples/playwright/src/tests/theia-main-menu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,17 @@ test.describe('Theia Main Menu', () => {
expect(await fileDialog.isVisible()).toBe(false);
});

test('Create file via New File menu and cancel', async () => {
const openFileEntry = 'New File...';
await (await menuBar.openMenu('File')).clickMenuItem(openFileEntry);
test('Create file via New File menu and accept', async () => {
await (await menuBar.openMenu('File')).clickMenuItem('New File...');
const quickPick = app.page.getByPlaceholder('Select File Type or Enter');
// type file name and press enter
await quickPick.fill('test.txt');
await quickPick.press('Enter');

// check file dialog is opened and accept with "Create File" button
// check file dialog is opened and accept with ENTER
const fileDialog = await app.page.waitForSelector('div[class="dialogBlock"]');
expect(await fileDialog.isVisible()).toBe(true);
await app.page.locator('#theia-dialog-shell').getByRole('button', { name: 'Create File' }).click();
await app.page.locator('#theia-dialog-shell').press('Enter');
expect(await fileDialog.isVisible()).toBe(false);

// check file in workspace exists
Expand Down
11 changes: 11 additions & 0 deletions packages/filesystem/src/browser/file-dialog/file-dialog-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ export class FileDialogWidget extends FileTreeWidget {
return attr;
}

protected override handleEnter(event: KeyboardEvent): boolean | void {
// Handle ENTER in the dialog to Accept.
// Tree view will just expand/collapse the node. This works also with arrow keys or SPACE.
return false;
}

protected override handleEscape(event: KeyboardEvent): boolean | void {
// Handle ESC in the dialog to Cancel and close the Dialog.
return false;
}

protected override createNodeClassNames(node: TreeNode, props: NodeProps): string[] {
const classNames = super.createNodeClassNames(node, props);
if (this.shouldDisableSelection(node)) {
Expand Down
Loading