Skip to content

Commit

Permalink
added the option to force a conversion to plain text on paste (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
robin7331 authored and chmln committed Jul 5, 2018
1 parent c017134 commit 3ac688f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ All keys are optional.
},

// limit content height if you wish. If not set, editor size will grow with content.
maxHeight: "500px"
maxHeight: "500px",

// set to 'true' this will insert plain text without styling when you paste something into the editor.
forcePlainTextOnPaste: true
}
```
Available Modules:
Expand Down
15 changes: 15 additions & 0 deletions src/editor/Editr.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ export default {
this.selection = this.saveSelection();
},
onPaste(e) {
e.preventDefault();
// get a plain representation of the clipboard
var text = e.clipboardData.getData("text/plain");
// insert that plain text text manually
document.execCommand("insertHTML", false, text);
},
syncHTML () {
if (this.html !== this.$refs.content.innerHTML)
this.innerHTML = this.html;
Expand All @@ -204,6 +214,11 @@ export default {
this.$refs.content.addEventListener("focus", this.onFocus);
this.$refs.content.addEventListener("input", this.onInput);
this.$refs.content.addEventListener("blur", this.onContentBlur, { capture: true });
if (this.mergedOptions.forcePlainTextOnPaste === true) {
this.$refs.content.addEventListener("paste", this.onPaste);
}
this.$refs.content.style.maxHeight = this.mergedOptions.maxHeight;
},
Expand Down

0 comments on commit 3ac688f

Please sign in to comment.