- Notifications
You must be signed in to change notification settings - Fork 352
Interactive code Gutenberg block #168
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
Here's a solution I found when I encountered the same issue with an instance of CodeMirror 5 inside a Gutenberg block. It's based on this issue comment in the Gutenberg repo: Undo / redo (keyboard shortcuts) affecting the whole document rather than the focussed TextControl. import { KeyboardShortcuts } from '@wordpress/components' import { rawShortcut } from '@wordpress/keycodes' const stop = (e) => e.stopImmediatePropagation() const shortcutOverrides = { tab: stop, [rawShortcut.shift('tab')]: stop, [rawShortcut.primary('[')]: stop, [rawShortcut.primary(']')]: stop, [rawShortcut.primary('a')]: stop, [rawShortcut.primary('d')]: stop, [rawShortcut.primary('z')]: stop, [rawShortcut.primaryShift('z')]: stop, // ... } <KeyboardShortcuts shortcuts={ shortcutOverrides }> <CodeMirror /> </KeyboardShortcuts>The workaround probably belongs in For a list of keycodes and modifiers provided by the |
| This is amazing @eliot-akira, thank you! |
| @eliot-akira that was it – plus a global 'cut' event handler (73d181e) |
| Glad to hear the little tip about Gutenberg keyboard shortcuts was useful. And good to know about capturing browser cut/copy/paste events - I'll be copying that snippet for my own use. :) From the issue where I got the idea, I think other people could benefit from the wrapper component |
1240074 to e8a2561 Compare f74b700 to 1622f9b Compare 786e3ac to 4bc8b85 Compare |
Other than that, this one seems good for merging. |
| This one is not ready for plugin directory yet (see the follow-up tasks at the top), but it's ready for |
Here I'm open sourcing the Gutenberg block behind my interactive Tag Processor tutorial
CleanShot.2023-03-24.at.16.58.38.mp4
Note how it supports multiple highlighting and execution modes!
Remaining tasks:
Follow-up tasks: