ProseMirror / prosemirror

The ProseMirror WYSIWYM editor
http://prosemirror.net/
MIT License
7.61k stars 336 forks source link

dropCursor doesn't appear when dragging a node that can appear at most once #1359

Closed jiegillet closed 1 year ago

jiegillet commented 1 year ago

Hello! First of all, thank you so much for working on prosemirror, it is a real pleasure to use.

In our editor, we have a node that can only appear at most once. The node, when it exists, can be dragged and dropped, but the dropcursor element does not appear.

It happens at this point, where the plugin calls dropPoint that eventually calls this.contentMatchAt(from).matchFragment(replacement, start, end) on this line, which doesn't match because the editor (rightfully) thinks that the node is already in use somewhere else.

The cursor should appear since it is legal to move the node.

Here is a test project that illustrates the situation. In case it gets deleted, the modification from the standard project are

const {nodes, marks} = require("prosemirror-schema-basic")

const myNodes = { 
  ...nodes,
  /// The top level document, the document can contain at most one unique_horizontal_rule
  doc: {
    content: "block* unique_horizontal_rule? block*"
  },
  /// A horizontal rule that can only appear once
  unique_horizontal_rule: {
    parseDOM: [{tag: "uniquehr"}],
    toDOM() { return ["hr", { style: "background-color: red;"}] }
  },
}

const schema = new Schema({nodes: myNodes, marks})

in index.js and

  <h3>Hello ProseMirror</h3>

  <p>The horizontal rule below is a normal one, it can be dragged around with the dropcursor</p>

  <hr>

  <p>The horizontal rule below is one that can only be in the document once, it can be dragged around, but the dropcursor doesn't appear</p>

  <uniquehr></uniquehr>

in index.html.

marijnh commented 1 year ago

Attached patch should improve this.

jiegillet commented 1 year ago

Thank you, that fixed it nicely :)