Closed paulirwin closed 2 years ago
I'd be happy to submit a PR with whichever solution below you feel is best.
Thanks ❤️
I am slightly busy atm. Let's just do Solution 1
as a short fix. It will be just 2-3 line changes. I will release this first once the changes are done. This issue can stay open until solution 2 or any other proper fix is implemented.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
Thanks @github-actions bot for the reminder 😄
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in the thread.
I'm submitting a
Description
For reference: https://github.com/sibiraj-s/ngx-editor/blob/e6a080d6c3e498a6b56801774ca0cc892a859c70/projects/ngx-editor/src/lib/Editor.ts#L117
The default plugins are added to the plugins array before the plugins provided in options. This works fine in most non-conflicting cases, but prevents creating custom keymaps for i.e. the Enter key, or using other ProseMirror plugins that use such keymaps. The default plugins add keymap bindings earlier in the pipeline that return
true
preventing further keymaps from being invoked. As far as I can tell, the only way around this currently is to setkeyboardShortcuts: false
in the options, and re-create the default keymap plugin by copying thegetKeyboardShortcuts
code (since that function is not exported). I've tried editing the views plugin array after creation and that breaks things without giving an error to the console. Copying thegetKeyboardShortcuts
method works okay, but then you lose the ability to benefit from community improvements and bugfixes to that code with npm updates.I wasn't quite sure whether to call this a bug report or a feature request, as it's somewhat both. As this excellent library was thoughtfully designed to be flexible and extensible, I would imagine that not being able to override keymaps by default would be an unintended bug. But at the same time, changing the order to put the default plugins last would be a breaking change, so I'm proposing a new config option to work around this issue.
I'd be happy to submit a PR with whichever solution below you feel is best, or if you have any other ideas on how to solve this problem.
Proposed Solution
Changing the order to put default plugins last (so that custom keymaps are evaluated first) would possibly be a breaking change, although if you wanted to go that route that would be fine by me.
Instead, I'd like to propose a new Options interface property of
preDefaultPlugins?: Plugin[];
. (Naming things is hard, I'm open to other name suggestions.) The default value for this new property in theDEFAULT_OPTIONS
object would be an empty array.A new line would be added below https://github.com/sibiraj-s/ngx-editor/blob/e6a080d6c3e498a6b56801774ca0cc892a859c70/projects/ngx-editor/src/lib/Editor.ts#L104:
And then the line up above spreading the plugin array would become:
Alternate Solution 1
Export the
getDefaultPlugins
,getKeyboardShortcuts
, etc methods in the public API viapublic_api.ts
. This would allow users that need custom keymaps to come first to setkeyboardShortcuts: false
, callgetKeyboardShortcuts
themselves, and add that to the array manually in whatever order they need. I think I'd prefer my proposed solution, as that doesn't have to disable and then re-enable defaults.Alternate Solution 2
Allow for providing a callback function to build the plugins array. For example:
Version Information
Browser
N/A