Prevent split `isolating` nodes

I was trying to make my custom nodes cannot be split, by adding isolating property to the schema.

It worked when I press Enter and Backspace. But when I copy and paste a block node, which cannot be put into my custom node, my custom node got split.

Is this behavior by design? How can I prevent this?

The demo schema is:

const doc = {
  content: 'block+',
};

const paragraph = {
  content: 'inline*',
  group: 'block',
  isolating: true,
  parseDOM: [{ tag: 'p' }],
  toDOM() {
    return ['p', 0];
  },
};

const text = {
  group: 'inline',
};

const horizontal_rule = {
  group: 'block',
  parseDOM: [{ tag: 'hr' }],
  toDOM() {
    return ['hr'];
  },
};

Yes. You could use a filterTransaction hook to prevent certain kinds of edits entirely, or try to handle this in a handlePaste function.

2 Likes