From 83fa879270e271dd487db2fccd48afeed61b59c6 Mon Sep 17 00:00:00 2001 From: White Hsu Date: Thu, 27 Oct 2022 23:55:59 +0800 Subject: [PATCH 1/2] [GH-#10878] Fix bug of Getting Start Widget Accept Focus Signed-off-by: White Hsu --- .../src/browser/getting-started-widget.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/getting-started/src/browser/getting-started-widget.tsx b/packages/getting-started/src/browser/getting-started-widget.tsx index 5f3b363c30f56..f9c8fb10decb6 100644 --- a/packages/getting-started/src/browser/getting-started-widget.tsx +++ b/packages/getting-started/src/browser/getting-started-widget.tsx @@ -17,7 +17,7 @@ import * as React from '@theia/core/shared/react'; import URI from '@theia/core/lib/common/uri'; import { injectable, inject, postConstruct } from '@theia/core/shared/inversify'; -import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget'; +import { Message, ReactWidget } from '@theia/core/lib/browser'; import { CommandRegistry, isOSX, environment, Path } from '@theia/core/lib/common'; import { WorkspaceCommands, WorkspaceService } from '@theia/workspace/lib/browser'; import { KeymapsCommands } from '@theia/keymaps/lib/browser'; @@ -111,6 +111,14 @@ export class GettingStartedWidget extends ReactWidget { this.update(); } + protected override onActivateRequest(msg: Message): void { + super.onActivateRequest(msg); + const htmlElement = document.getElementById('getting.started.widget'); + if (htmlElement) { + htmlElement?.focus(); + } + } + /** * Render the content of the widget. */ From 52f18c49a5d1c911b09c328bc340bc2d725e9457 Mon Sep 17 00:00:00 2001 From: White Hsu Date: Thu, 27 Oct 2022 23:55:59 +0800 Subject: [PATCH 2/2] [GH-#10878] Fix bug of Getting Start Widget Accept Focus Signed-off-by: White Hsu == To modify getting-started-contribution.ts to pass activate to the openView methods. To focus on the first available link in getting-started-widget.tsx. [Question] But the warning below still exists. May I ask your kind suggestion? Thank you very much. -- WARN Widget was activated, but did not accept focus after 2000ms: getting.started.widget -- --- .../src/browser/getting-started-contribution.ts | 4 ++-- .../src/browser/getting-started-widget.tsx | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/getting-started/src/browser/getting-started-contribution.ts b/packages/getting-started/src/browser/getting-started-contribution.ts index cc889b31e0e68..152419d894f7e 100644 --- a/packages/getting-started/src/browser/getting-started-contribution.ts +++ b/packages/getting-started/src/browser/getting-started-contribution.ts @@ -51,14 +51,14 @@ export class GettingStartedContribution extends AbstractViewContribution { if (!this.workspaceService.opened) { this.stateService.reachedState('ready').then( - () => this.openView({ reveal: true }) + () => this.openView({ reveal: true, activate: true }) ); } } override registerCommands(registry: CommandRegistry): void { registry.registerCommand(GettingStartedCommand, { - execute: () => this.openView({ reveal: true }), + execute: () => this.openView({ reveal: true, activate: true }), }); } diff --git a/packages/getting-started/src/browser/getting-started-widget.tsx b/packages/getting-started/src/browser/getting-started-widget.tsx index 5f3b363c30f56..3bfb0933b4a63 100644 --- a/packages/getting-started/src/browser/getting-started-widget.tsx +++ b/packages/getting-started/src/browser/getting-started-widget.tsx @@ -17,7 +17,7 @@ import * as React from '@theia/core/shared/react'; import URI from '@theia/core/lib/common/uri'; import { injectable, inject, postConstruct } from '@theia/core/shared/inversify'; -import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget'; +import { Message, ReactWidget } from '@theia/core/lib/browser'; import { CommandRegistry, isOSX, environment, Path } from '@theia/core/lib/common'; import { WorkspaceCommands, WorkspaceService } from '@theia/workspace/lib/browser'; import { KeymapsCommands } from '@theia/keymaps/lib/browser'; @@ -111,6 +111,14 @@ export class GettingStartedWidget extends ReactWidget { this.update(); } + protected override onActivateRequest(msg: Message): void { + super.onActivateRequest(msg); + const elArr = document.getElementsByClassName('gs-action-container'); + if (elArr && elArr.length > 0) { + (elArr[0] as HTMLElement).focus(); + } + } + /** * Render the content of the widget. */