Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate drags from drops in stopEvent #2070

Merged
merged 2 commits into from
Oct 22, 2021

Conversation

thatsjonsense
Copy link
Contributor

@thatsjonsense thatsjonsense commented Oct 21, 2021

Problem

When you try to drop something on the edges of a NodeView, outside the contentDOM, it looks like it should be droppable because dropCursor shows a line in the correct place. But it doesn't actually go through, or it goes through as a copy instead of a move, because stopEvent triggers and prevents the drop event from propagating effectively.

More details: ProseMirror/prosemirror#1208

Solution

Separate the logic for handling drag events from drop events

const isInput = ['INPUT', 'BUTTON', 'SELECT', 'TEXTAREA'].includes(target.tagName)
|| target.isContentEditable
|| (target.isContentEditable && !isDropEvent)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you tell me why this is related to the isInput check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The following line will stop any event that matches this isInput check. But I found that all drops were being classified as inputs because this check is so broad, just because they landed inside inside the content editable. This prevents ProseMirror's handleDrop from running. handleDrop is what removes the original slice after you drop. Without this change, it would always duplicate.

An alternative would be to change the line below to

    if (isInput && !isDropEvent) {
      return true
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah right, that isContentEditable check initially was for detecting nested editors. Maybe I have to improve that.

An alternative would be to change the line below to
if (isInput && !isDropEvent) {
return true
}

better!

And do you think this is related to #1938?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, I have a feeling #1938 would be solved by the change on line 169 below to always return false if it's a drop event

@philippkuehn philippkuehn merged commit bebaa40 into ueberdosis:main Oct 22, 2021
@philippkuehn
Copy link
Contributor

great! thanks!

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.

2 participants