-
Notifications
You must be signed in to change notification settings - Fork 67
Fix/call plugin keyBindingFns #445
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
Conversation
thibaudcolas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking pretty spot on @jacobtoppm!
I’d like to see two additions to this:
- A demo (Storybook story) of a plugin leveraging this, so we have a way to manually test this works as expected.
- An additional unit test that demonstrates #246 is indeed fixed – demoing that the editor’s built-in keyBindingFn doesn’t swallow all keyboard shortcuts.
For the demo, looking at what we have currently, you could:
- Change one of the existing ones – for example, adding a shortcut to insert embeds or section breaks.
- Add something else that might be simpler to implement – for example, showing a
window.alertwhen a keyboard shortcut is pressed. I think that would be ok enough, but ideally implementing something that’s still relevant to real-world use cases.
Co-authored-by: Thibaud Colas <thibaudcolas@gmail.com>
4ffc5af to
fa4c252
Compare
thibaudcolas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working really well, picked up a few small things!
| // Hack relying on the internals of Draft.js. | ||
| // See https://github.com/facebook/draft-js/pull/869 | ||
| // $FlowFixMe | ||
| const IS_MAC_OS = isOptionKeyCommand({ altKey: "test" }) === "test"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel like I might want to have this be exported by Draftail, otherwise it’ll be impossible for people to display shortcuts like this without resorting to the hack. Maybe for another PR though.
Currently, as described in #246, Draftail does not call plugin
keyBindingFns, preventing custom keyboard shortcuts from being used.This PR addresses this by passing the Draftail
keyBindingFnas an extra, final plugin to the pluginEditorcomponent instead. This is done so that:keyBindingFncan continue to prevent Draft responding overly sensitively to keyboard shortcuts (otherwise we could simply use thedefaultKeyBindingsoption of the plugins editor) by returning undefinedI haven't added this to the documentation yet - as it's just a fix, I'm not sure where it should go, but happy to add if you think it needs a mention somewhere. Tested in latest Chrome and Firefox on Ubuntu.