We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
There is no way to handle keydown event like Ctrl+S on focus is in editor
Ctrl+S
can we add listener for keydown event?
crepe.on((listener) => { listener.onKeydown: (event, ctx) => { if (event.ctrlKey && event.key === 's') { event.preventDefault(); // handle Ctrl+S keys } } })
Trying this without success - it works only if focus is not in editor it appears that keydown event is handled in milkdown editor?
const onKeydown = useCallback( (e: KeyboardEvent) => { if (e.ctrlKey && e.key === 's') { saveDescription(); return } }, []) useEffect(() => { window.addEventListener('keydown', onKeydown); return () => { window.removeEventListener('keydown', onKeydown); }; }, [onKeydown]);
The text was updated successfully, but these errors were encountered:
https://milkdown.dev/docs/api/utils#shortcut-shortcut-fnctx-ctx-keymap-shortcut
Example:
milkdown/packages/plugins/preset-commonmark/src/node/heading.ts
Line 195 in 5284c13
Sorry, something went wrong.
$useKeymap works. Thanks!
$useKeymap
This is my implementation for Crepe editor:
import { commandsCtx } from '@milkdown/kit/core'; import { $useKeymap, $command } from "@milkdown/kit/utils"; const saveCommand = $command('saveCommand', (ctx) => (options) => { return (state, dispatch) => { saveDescription(); return true; } }); const saveKeyMap = $useKeymap("saveKeymap", { saveDescription: { shortcuts: "Ctrl-s", command: (ctx) => { const commands = ctx.get(commandsCtx) return () => commands.call(saveCommand.key) }, }, }); crepe.editor.use([saveCommand,saveKeyMap].flat());
Saul-Mirone
No branches or pull requests
Initial checklist
Problem
There is no way to handle keydown event like
Ctrl+S
on focus is in editorSolution
can we add listener for keydown event?
Alternatives
Trying this without success - it works only if focus is not in editor it appears that keydown event is handled in milkdown editor?
The text was updated successfully, but these errors were encountered: