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

quill-paste-smart.js:3 Uncaught TypeError: e.preventDefault is not a function #33

Open
PaulleDemon opened this issue Nov 20, 2023 · 3 comments

Comments

@PaulleDemon
Copy link

Here is the codepen.

I can't paste because of this issue. I hope you'll be able to resolve this. Thanks

@cskri
Copy link

cskri commented Dec 28, 2023

I am experiencing the same issue, have you found a solution yet?

@lelit
Copy link

lelit commented Jan 3, 2024

It seems that the relevant code in Quill v2 changed considerably: in particular the signature of the onPaste() callback used to accept a single event argument, but now it takes a delta and an object with text and html selection.

@PaulleDemon
Copy link
Author

Hey sorry for late reply, you should actually change some parts of the source code.

If you just want a plain paste use the below code:

class PlainTextClipboard extends Quill.import('modules/clipboard') {
    constructor(quill, options) {
        super(quill, options)
        // Parse the toolbar configuration of the incoming module (that is, the two-dimensional array described earlier) and render the toolbar
    }
    onCapturePaste(e) {
        e.preventDefault()
        console.log("pasting")
        const range = this.quill.getSelection(true)
        const text = e.clipboardData.getData('text/plain')
       
        this.quill.deleteText(range.index, range.length, Quill.sources.USER)

        this.quill.insertText(range.index, text, Quill.sources.USER)
        this.quill.setSelection(range.index + text.length, Quill.sources.SILENT)
    }
}
  

make sure to add the module to quill

if you want to modify the source code, clone the repo and make changes in the onpaste function.

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

No branches or pull requests

3 participants