The content of non-editable node is still editable

I defined a NodeSpec

    label: {
      content: 'text*',
      defining: true,
      atom: true,
      selectable: false,
      parseDOM: [{tag: 'label'}],
      toDOM() { return ['label', {contenteditable: false}, 0] }
    }

Note in toDOM, contenteditable is set to false.

However, when you select part of the text in a lable by mouse and hit delete key, this part of text is removed.

And if you select all the document (Ctrl-a), and hit delete, everything goes away.

I am not sure if this is intended feature. But how to define a non-editable, non-deletable node?

1 Like

You could make the label text an attribute, rather than content. That would prevent ProseMirror from trying to manage it.

But when you select across a node and press delete, the selected range is going to be deleted—whether individual nodes in the range are editable isn’t relevant there. The only way to prevent that is to filter transactions.

1 Like

Thank you for your hint.

By filter transations, do you mean the filterTransaction and appendTransaction in PluginSpec? So when the current transaction is a selection-deleting/replacing action and the selection contains the node I want to preserve (I don’t know how to implement this judgement), I append a new transaction to restore the node, am I right?

BTW, would it be possible to support defining a NodeSpec that is non-deletable?

I think it is quite common. If this is supported, I would define such nodes like title, author and etc. and put them in the editor to take full advantage of prosemirror’s function, instead of simple input or textarea elements outside of the editor.

When the user select all the document and hit delete, they would not be deleted (the element tag in the editor is preserved, while the content may be removed), since they are essential to a document.

1 Like

Yes, that, or simply filter out transactions that delete such a node (though then the delete won’t have any effect at all).

No, that’s too high-level, and hard to define in a general way, for the core library. It could be a plugin, I guess.

Ok. Fair enough. And thank you.