Skip to content

[6.x] Only remove Bard set when backspace key is hit#14189

Merged
jasonvarga merged 2 commits into6.xfrom
removing-bard-sets
Mar 12, 2026
Merged

[6.x] Only remove Bard set when backspace key is hit#14189
jasonvarga merged 2 commits into6.xfrom
removing-bard-sets

Conversation

@duncanmcclean
Copy link
Copy Markdown
Member

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

@andjsch
Copy link
Copy Markdown
Contributor

andjsch commented Mar 10, 2026

This is nice. Had that happen in v5 also from time to time.

Copy link
Copy Markdown
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 handleKeyDown instead of per-key shortcuts. One handler, no key enumeration, and all printable keys are covered. Example—add a third plugin in addProseMirrorPlugins():

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 the NodeSelection import for the selection instanceof NodeSelection check. This avoids maintaining a list of keys and closes the gap for keys like !, @, #, etc.

Copy link
Copy Markdown
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️

@jasonvarga
Copy link
Copy Markdown
Member

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.

@jasonvarga jasonvarga merged commit 4d17134 into 6.x Mar 12, 2026
17 checks passed
@jasonvarga jasonvarga deleted the removing-bard-sets branch March 12, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confusing UX in bard sets and removing sets is too easy

3 participants