Quill: How can I disable Clipboard module?

Created on 30 Jan 2017  路  2Comments  路  Source: quilljs/quill

Hi, I just don't to use the Clipboard, i.e. I just want to copy plain text, I read the documentation but I couldn't find some config to do that. Please, I am aware that this issue doesn't comply with the guidelines, can't I just get the answer if it's simple before closing it? Thanks.

Most helpful comment

I couldn't get the example to work, so I created this. Hopefully it helps someone else.

https://gist.github.com/ryanhaney/d4d205594b2993224b8ad111cebe1a13

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

All 2 comments

There is no quick configuration for plain text pasting. You can provide your own Clipboard module if Quill's does not suit you: http://quilljs.com/docs/modules/. The code example there happens to be exactly a plain text clipboard but it is just a code example for explanation and demonstration purposes.

I couldn't get the example to work, so I created this. Hopefully it helps someone else.

https://gist.github.com/ryanhaney/d4d205594b2993224b8ad111cebe1a13

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
Was this page helpful?
0 / 5 - 0 ratings

Related issues

sachinrekhi picture sachinrekhi  路  49Comments

tkw722 picture tkw722  路  32Comments

artaommahe picture artaommahe  路  32Comments

benbro picture benbro  路  34Comments

che3vinci picture che3vinci  路  39Comments