Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

t/90 EditingKeystrokeHandler should prevent default only for commands #91

Merged
merged 3 commits into from
Jun 20, 2017

Conversation

oleq
Copy link
Member

@oleq oleq commented Jun 14, 2017

Suggested merge commit message (convention)

Fix: EditingKeystrokeHandler should prevent default only for commands. Closes ckeditor/ckeditor5#2918.

@oleq oleq requested a review from Reinmar June 14, 2017 12:33
@Reinmar
Copy link
Member

Reinmar commented Jun 15, 2017

It blows up undo and basic-styles tests.

Besides that, it fixes the issue. But I'd like to understand one thing – why was listenTo() overridden before and why it isn't needed any more? Some leftover?

@oleq
Copy link
Member Author

oleq commented Jun 19, 2017

It blows up undo and basic-styles tests.

why was listenTo() overridden before and why it isn't needed any more? Some leftover?

Before, preventDefault was exclusive for keydown events only.

In my fix, it works at the KH#press() level because the code deciding whether to preventDefault or not has moved to EKH#set(). Thus the custom listenTo is no longer necessary.

At first, I wanted to leave things unchanged with overridden EKH#listenTo() but the problem is there's no way to tell whether it's a "command keystroke" or "callback keystroke" there, no way to decide whether preventDefault() or not without making the code much more complex (press() only tells if was handled or not).

As the logic moved to EKH#set() things became a little bit more complex, e.g. those undo and basic-style tests have blown up because preventDefault() is called in KH#press(), which means

const wasHandled = editor.keystrokes.press( {
	keyCode: keyCodes.b,
	ctrlKey: true
} );

is not enough any more. It was enough was because preventDefault() happened in EKH#listenTo(), not KH#press(). That's why you need to provide the mocks to avoid errors

const wasHandled = editor.keystrokes.press( {
	keyCode: keyCodes.b,
	ctrlKey: true,
	preventDefault: sinon.spy(),
	stopPropagation: sinon.spy()
} );

and TBH I totally hate it but have no other idea how to handle it. To get back to the preventDefault() at the listenTo() level we'd need to pass an information there whether it's a "command keystroke" or "callback keystroke", which would need to be saved first by EKH#set() and then passed via KH#press(). Any ideas?

@Reinmar
Copy link
Member

Reinmar commented Jun 20, 2017

and TBH I totally hate it but have no other idea how to handle it.

I think that the change is good. It makes sense.

I also don't like the fact that press() needs to be called with the entire KeyEventData object, but it should've been called with it in the past too. So the solution to that could be to allow easily mocking this object for tests.

@Reinmar Reinmar merged commit 82ff39a into master Jun 20, 2017
@Reinmar Reinmar deleted the t/90 branch June 20, 2017 08:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EditingKeystrokeHandler should prevent default only for commands
2 participants