"Discontiguous selection is not supported"error when calling Selection.addRange(), fixes #17

This commit is contained in:
Nik Butenko 2015-09-30 22:26:35 +10:00
parent bcd1512365
commit c3ff179110
2 changed files with 7 additions and 1 deletions

View File

@ -25,7 +25,8 @@
"babelify": "^6.3.0",
"browserify": "^11.2.0",
"delegate-events": "^1.1.1",
"tiny-emitter": "^1.0.0"
"tiny-emitter": "^1.0.0",
"toggle-selection": "^1.0.3"
},
"devDependencies": {
"karma": "^0.13.10",

View File

@ -1,3 +1,5 @@
import deselectCurrent from 'toggle-selection';
/**
* Inner class which performs selection from either `text` or `target`
* properties and then executes copy or cut operations.
@ -92,12 +94,15 @@ class ClipboardAction {
this.selectedText = this.target.value;
}
else {
const reselectPrevious = deselectCurrent();
let range = document.createRange();
let selection = window.getSelection();
range.selectNodeContents(this.target);
selection.addRange(range);
this.selectedText = selection.toString();
reselectPrevious();
}
this.copyText();