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

Tests in classic editor #15901

Merged
merged 5 commits into from
Apr 2, 2024

Conversation

mremiszewski
Copy link
Contributor

Suggested merge commit message (convention)

Tests (classic-editor): Add tests for menu bar. Related to #15894.


Additional information

For example – encountered issues, assumptions you had to make, other affected tickets, etc.

@mremiszewski mremiszewski requested a review from oleq February 22, 2024 08:50
} );
} );

describe( 'Restoring focus on Esc key press', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a follow-up: We're going to need this kind of logic for the menu bar as well.

editor.keystrokes.set( 'Esc', ( data, cancel ) => {
const focusedToolbarDef = this._getCurrentFocusedToolbarDefinition();
if ( !focusedToolbarDef ) {
return;
}
// Bring focus back to where it came from before focusing the toolbar:
// 1. If it came from outside the engine view (e.g. source editing), move it there.
if ( lastFocusedForeignElement ) {
lastFocusedForeignElement.focus();
lastFocusedForeignElement = null;
}
// 2. There are two possibilities left:
// 2.1. It could be that the focus went from an editable element in the view (root or nested).
// 2.2. It could be the focus went straight to the toolbar before even focusing the editing area.
// In either case, just focus the view editing. The focus will land where it belongs.
else {
editor.editing.view.focus();
}
// Clean up after the toolbar if there is anything to do there.
if ( focusedToolbarDef.options.afterBlur ) {
focusedToolbarDef.options.afterBlur();
}
cancel();
} );

I coded the prototype as fast as possible so I didn't consider cases where the focus must get back to some other place (e.g. source editing).

I suppose EditorUI#addMenuBar corresponding to addToolbar would be a good idea. Because currently, the keystroke handling code for the menu bar is in ClassicEditorUI, and if sb wanted to build their editor, they wouldn't be able to add a menu bar without duplicating the code.

cc @DawidKossowski

@mremiszewski mremiszewski changed the base branch from ck/app-menu-bar to ck/app-menu-bar-unit-tests April 2, 2024 13:56
@oleq oleq merged commit a5a0e33 into ck/app-menu-bar-unit-tests Apr 2, 2024
1 check was pending
@oleq oleq deleted the ck/app-menu-bar-classic-editor branch April 2, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants