diff --git a/packages/application/src/index.ts b/packages/application/src/index.ts index c0f50948e..3898e0890 100644 --- a/packages/application/src/index.ts +++ b/packages/application/src/index.ts @@ -188,6 +188,20 @@ export class Application { return this._delegate.promise; } + /** + * Getter and setter for the bubblingKeydown experimental flag. + * + * @experimental + */ + get bubblingKeydown(): boolean { + return this._bubblingKeydown; + } + set bubblingKeydown(value: boolean) { + document.removeEventListener('keydown', this, !this._bubblingKeydown); + this._bubblingKeydown = value; + document.addEventListener('keydown', this, !this._bubblingKeydown); + } + /** * Get a plugin description. * @@ -506,6 +520,8 @@ export class Application { // Mark the application as started; this._started = true; + this._bubblingKeydown = options.bubblingKeydown || false; + // Parse the host ID for attaching the shell. const hostID = options.hostID || ''; @@ -606,8 +622,11 @@ export class Application { * A subclass may reimplement this method as needed. */ protected addEventListeners(): void { + if (this._bubblingKeydown) { + console.log('The keydown events are handled during bubbling phase'); + } document.addEventListener('contextmenu', this); - document.addEventListener('keydown', this, true); + document.addEventListener('keydown', this, !this._bubblingKeydown); window.addEventListener('resize', this); } @@ -663,6 +682,7 @@ export class Application { private _plugins = new Map(); private _services = new Map, string>(); private _started = false; + private _bubblingKeydown = false; } /** @@ -715,6 +735,14 @@ export namespace Application { * This will override `startPlugins` and any `autoStart` plugins. */ ignorePlugins?: string[]; + + /** + * Whether to capture keydown event at bubbling or capturing (default) phase for + * keyboard shortcuts. + * + * @experimental + */ + bubblingKeydown?: boolean; } } diff --git a/review/api/application.api.md b/review/api/application.api.md index cec107714..3c5637c1a 100644 --- a/review/api/application.api.md +++ b/review/api/application.api.md @@ -17,6 +17,8 @@ export class Application { activatePlugin(id: string): Promise; protected addEventListeners(): void; protected attachShell(id: string): void; + get bubblingKeydown(): boolean; + set bubblingKeydown(value: boolean); readonly commands: CommandRegistry; readonly contextMenu: ContextMenu; deactivatePlugin(id: string): Promise; @@ -46,6 +48,7 @@ export namespace Application { shell: T; } export interface IStartOptions { + bubblingKeydown?: boolean; hostID?: string; ignorePlugins?: string[]; startPlugins?: string[];