Created
July 10, 2018 00:03
-
-
Save prodrammer/d4d205594b2993224b8ad111cebe1a13 to your computer and use it in GitHub Desktop.
Example enforcing plain text paste in Quill.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Quill from 'quill' | |
import PlainClipboard from './PlainClipboard' | |
Quill.register('modules/clipboard', PlainClipboard, true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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.