Slate: HTML content being pasted twice

Created on 29 Aug 2019  路  4Comments  路  Source: ianstormtaylor/slate

Do you want to request a _feature_ or report a _bug_?

Bug

What's the current behavior?

twice

When HTML content is pasted, it is pasting it twice.

  1. Copy some content from a webpage, even a line.
  2. https://www.slatejs.org/#/paste-html
  3. Paste.

What's the expected behavior?

Paste only once.

Most helpful comment

Hello
Need to change the onPaste

  onPaste = (event, editor, next) => {
    event.preventDefault()  // <---- add me

    const transfer = getEventTransfer(event)
    if (transfer.type !== 'html') return next()
    const { document } = serializer.deserialize(transfer.html)
    editor.insertFragment(document)
  }

link

All 4 comments

As far as I can tell, the defect is that the onPaste handler is firing a second time with a plain text paste as if return next() was being called to resume the plugin stack after the html is deserialized and inserted
https://jsfiddle.net/1nzto9vd/1/

Pasting also doesn't respect line breaks

That's probably related to how insert fragment works

Hello
Need to change the onPaste

  onPaste = (event, editor, next) => {
    event.preventDefault()  // <---- add me

    const transfer = getEventTransfer(event)
    if (transfer.type !== 'html') return next()
    const { document } = serializer.deserialize(transfer.html)
    editor.insertFragment(document)
  }

link

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ianstormtaylor picture ianstormtaylor  路  3Comments

ianstormtaylor picture ianstormtaylor  路  3Comments

bunterWolf picture bunterWolf  路  3Comments

markolofsen picture markolofsen  路  3Comments

YurkaninRyan picture YurkaninRyan  路  3Comments