Skip to content

Instantly share code, notes, and snippets.

@prodrammer
Created July 10, 2018 00:03
Show Gist options
  • Save prodrammer/d4d205594b2993224b8ad111cebe1a13 to your computer and use it in GitHub Desktop.
Save prodrammer/d4d205594b2993224b8ad111cebe1a13 to your computer and use it in GitHub Desktop.
Example enforcing plain text paste in Quill.
import Quill from 'quill'
import PlainClipboard from './PlainClipboard'
Quill.register('modules/clipboard', PlainClipboard, true)
import Quill from 'quill'
const Clipboard = Quill.import('modules/clipboard')
const Delta = Quill.import('delta')
class PlainClipboard extends Clipboard {
onPaste (e) {
e.preventDefault()
const range = this.quill.getSelection()
const text = e.clipboardData.getData('text/plain')
const delta = new Delta()
.retain(range.index)
.delete(range.length)
.insert(text)
const index = text.length + range.index
const length = 0
this.quill.updateContents(delta, 'silent')
this.quill.setSelection(index, length, 'silent')
this.quill.scrollIntoView()
}
}
export default PlainClipboard
@clonn
Copy link

clonn commented Nov 27, 2018

_vue_quill_editor___default.a.register is not a function

I have no idea what happen

// -----

Updated,

that is my fault, have to use origin quill module to register plugin

@gengxueke
Copy link

i have a problem
i use this in my project
but i found that between line , they have a \n ,i do not know why
please help me.
like this
2019-01-21 4 27 53

@youngbobby
Copy link

@clonn How are you able to get this working on vue-quill-editor? All I get is an empty box with error:

[Vue warn]: Error in mounted hook: "TypeError: moduleClass is not a constructor"

Screen Shot 2019-06-15 at 4 37 07 AM

I have followed all the instructions here. cc: @ryanhaney

@marcerkol78
Copy link

Hie everyone !
do you know how is this solution with angular 8 ?

i don't want change de source code of quill js. Because i work with my team.
How can i use this solutions only with ngx-quill please ?

i only want the text in the clipboard (no style, pictures or html code).

@prodrammer
Copy link
Author

@marcerkol78, perhaps the author of ngx-quill can help with your questions. You'll need to find out how to register a custom clipboard module with Quill.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment