[6.x] Only remove Bard set when backspace key is hit#14189
Conversation
|
This is nice. Had that happen in v5 also from time to time. |
jasonvarga
left a comment
There was a problem hiding this comment.
I don't love that we have to whitelist every character. I'm sure we've missed some.
Instead, we should just allow the ones we want.
Here's the AI suggestion. I haven't tested it:
Use a ProseMirror plugin with
handleKeyDowninstead of per-key shortcuts. One handler, no key enumeration, and all printable keys are covered. Example—add a third plugin inaddProseMirrorPlugins():import { NodeSelection } from '@tiptap/pm/state'; // In addProseMirrorPlugins(), add: new Plugin({ key: new PluginKey('setBlockCharacterInput'), props: { handleKeyDown(view, event) { const { state } = view; const { selection } = state; if (!(selection instanceof NodeSelection) || selection.node.type !== type) return false; const k = event.key; if (k === 'Backspace' || k === 'Delete' || k === 'Enter' || k === 'Escape' || k === 'Tab') return false; if (k.length === 1) return true; // block single character input return false; }, }, }),Then remove
addKeyboardShortcuts()and keep theNodeSelectionimport for theselection instanceof NodeSelectioncheck. This avoids maintaining a list of keys and closes the gap for keys like!,@,#, etc.
|
This prevents deletions when you focus the bard set directly. You can still delete the set when you highlight around the bard set. This is still a big improvement. As shown in the issue, the issue he runs into is that he clicks on things within the bard set and accidentally deletes the whole thing with a keystroke. That part is solved. 👍 If you select around the bard set, that is more intentional so deleting that way is fine. Maybe can be improved later somehow. |
This pull request fixes an issue where pressing any character key while a Bard set is selected would delete the set.
This was happening because TipTap/ProseMirror's default behavior for selected nodes is to replace them when typing.
This PR fixes it by adding keyboard shortcuts that intercept printable character keys (letters, numbers, punctuation) when a set node is selected, preventing accidental deletion.
Backspace and Delete keys still work normally for intentional removal.
Partially fixes #14185