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

Keydown event at bubbling phase #635

Merged
merged 4 commits into from
Sep 25, 2023
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
30 changes: 29 additions & 1 deletion packages/application/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ export class Application<T extends Widget = Widget> {
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.
*
Expand Down Expand Up @@ -506,6 +520,8 @@ export class Application<T extends Widget = Widget> {
// Mark the application as started;
this._started = true;

this._bubblingKeydown = options.bubblingKeydown || false;
brichet marked this conversation as resolved.
Show resolved Hide resolved

// Parse the host ID for attaching the shell.
const hostID = options.hostID || '';

Expand Down Expand Up @@ -606,8 +622,11 @@ export class Application<T extends Widget = Widget> {
* 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);
}

Expand Down Expand Up @@ -663,6 +682,7 @@ export class Application<T extends Widget = Widget> {
private _plugins = new Map<string, Private.IPluginData>();
private _services = new Map<Token<any>, string>();
private _started = false;
private _bubblingKeydown = false;
}

/**
Expand Down Expand Up @@ -715,6 +735,14 @@ export namespace Application {
* This will override `startPlugins` and any `autoStart` plugins.
*/
ignorePlugins?: string[];

brichet marked this conversation as resolved.
Show resolved Hide resolved
/**
* Whether to capture keydown event at bubbling or capturing (default) phase for
* keyboard shortcuts.
*
* @experimental
*/
bubblingKeydown?: boolean;
brichet marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
3 changes: 3 additions & 0 deletions review/api/application.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export class Application<T extends Widget = Widget> {
activatePlugin(id: string): Promise<void>;
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<string[]>;
Expand Down Expand Up @@ -46,6 +48,7 @@ export namespace Application {
shell: T;
}
export interface IStartOptions {
bubblingKeydown?: boolean;
hostID?: string;
ignorePlugins?: string[];
startPlugins?: string[];
Expand Down
Loading