mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
"Discontiguous selection is not supported"error when calling Selection.addRange(), fixes #17
This commit is contained in:
parent
bcd1512365
commit
c3ff179110
@ -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",
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user