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
@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