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

The keystrokes are no longer conflicting on MacOS #9057

Merged
merged 17 commits into from
Feb 23, 2021
Merged

The keystrokes are no longer conflicting on MacOS #9057

merged 17 commits into from
Feb 23, 2021

Conversation

niegowski
Copy link
Contributor

@niegowski niegowski commented Feb 20, 2021

Suggested merge commit message (convention)

Fix (utils): The keystrokes are no longer conflicting on macOS. Closes #5705.

Feature (utils): Added forced modifier key (Ctrl!) for keystrokes that should not be mapped to Command on macOS.

Other (engine): The KeyObserver should provide information about metaKey being pressed.

Other (list): The to-do list item toggle keystroke changed to Ctrl+Enter (Cmd+Enter on Mac).

Internal (typing): Any keypress while the Cmd key is pressed is not a typing keystroke.

BREAKING CHANGE: On macOS keystrokes with the Ctrl modifier will not be handled unless the modifier is registered as the forced one (for example: Ctrl!+A will not be translated to Cmd+A on macOS).

BREAKING CHANGE (list): The to-do list item toggle keystroke changed to Ctrl+Enter (Cmd+Enter on Mac).


Additional information

@maxbarnas maxbarnas self-requested a review February 22, 2021 09:21
@@ -23,7 +23,7 @@ export default class EnterObserver extends Observer {
const doc = this.document;

doc.on( 'keydown', ( evt, data ) => {
if ( this.isEnabled && data.keyCode == keyCodes.enter ) {
if ( this.isEnabled && data.keyCode == keyCodes.enter && !data.ctrlKey && !data.metaKey ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious why we want to not act on Ctrl+Enter/Cmd+Enter. After a brief check I didn't find it very consistent across editors:

  • Google Docs creates a new paragraph on Cmd+Enter,
  • Slack / Apple Pages create a new paragraph on Ctrl+Enter,
  • Notion does the same as the new code above :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because editor.keystrokes is not stopping the original event so it splits the list item while pressing Cmd+Enter. Now I'm wondering if we should change the KeystrokeHandler behavior or this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm changing it, to-do list will use 'keydown' listener so it can be stopped in the context of to-do list.

packages/ckeditor5-list/src/todolistediting.js Outdated Show resolved Hide resolved
@@ -97,6 +102,7 @@ export function parseKeystroke( keystroke ) {

return keystroke
.map( key => ( typeof key == 'string' ) ? getCode( key ) : key )
.map( key => env.isMac && key == keyCodes.ctrl ? keyCodes.cmd : key )
Copy link
Contributor

@maxbarnas maxbarnas Feb 22, 2021

Choose a reason for hiding this comment

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

Does this line mean you cannot assign Ctrl+... keystroke on a Mac? Oh, I see in the old code it was automatically assumed that Ctrl on Windows equals . Still surprising :)

Copy link
Contributor Author

@niegowski niegowski Feb 22, 2021

Choose a reason for hiding this comment

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

Yes. Otherwise, we would need to provide some "force" specifier or provide keystroke alternative for MacOS.

Copy link
Member

Choose a reason for hiding this comment

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

Does this line means you cannot assign Ctrl+... keystroke on a Mac?

I'm worried about existing integrations here. Changing keystrokes in our features to resolve conflicts is a breaking change but disabling keystrokes in 3rd-party integrations is a whole new level. Just to clarify: there will be no way to use Ctrl+whatever on Mac after this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After a talk with @Reinmar we decided that we will introduce Ctrl! as a forced Ctrl key that won't get mapped to Cmd on macOS. This is because some integrators or external features might want to use keystrokes that are not available after mapping to Cmd (for example Cmd+Q, Cmd+T, Cmd+W, etc.) but are available as Ctrl+Q, Ctrl+T, Ctrl+W.

packages/ckeditor5-utils/src/keyboard.js Show resolved Hide resolved
@niegowski
Copy link
Contributor Author

Ready for another review round.

@niegowski niegowski requested review from maxbarnas and oleq February 22, 2021 16:49
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.

Some CKEditor keyboard shortcuts conflict with Mac OS shortcuts
3 participants