Advertisement
Guest User

mysuper784

a guest
Jan 22nd, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. public copySelectedTextToClipboard() {
  2. const selection = getSelectedText();
  3. if (selection != "") {
  4. window.navigator.clipboard.writeTextToClipboard(this.value)
  5. const inputfield = this.$refs.input as any
  6. inputfield.focus()
  7. }
  8. else{
  9. window.navigator.clipboard.writeTextToClipboard(selection)
  10. }
  11. }
  12. public cutSelectedTextToClipboard() {
  13. document.execCommand("cut")
  14. }
  15. public pasteSelectedTextFromClipboard() {
  16. const inputfield = this.$refs.input as any
  17. inputfield.focus()
  18. document.execCommand("paste")
  19. }
  20.  
  21. private getSelectedText() {
  22. var text = "";
  23. if (typeof window.getSelection != "undefined") {
  24. text = window.getSelection().toString();
  25. } else if (typeof document.selection != "undefined" && document.selection.type == "Text") {
  26. text = document.selection.createRange().text;
  27. }
  28. return text;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement