This commit is contained in:
Rainer Simon 2020-05-14 10:36:47 +02:00
parent a66df4950c
commit 1108859299
2 changed files with 18 additions and 5 deletions

View File

@ -59,7 +59,7 @@ export default class SelectionHandler extends EventEmitter {
const spans = this.highlighter.wrapRange(selectedRange);
spans.forEach(span => span.className = 'r6o-selection');
this._clearNativeSelection();
this._hideNativeSelection();
this.emit('select', {
selection: stub,
@ -70,7 +70,14 @@ export default class SelectionHandler extends EventEmitter {
}
}
_clearNativeSelection = () => {
_hideNativeSelection = () => {
this.el.classList.add('hide-selection');
}
clearSelection = () => {
this._currentSelection = null;
// Remove native selection, if any
if (window.getSelection) {
if (window.getSelection().empty) { // Chrome
window.getSelection().empty();
@ -80,10 +87,8 @@ export default class SelectionHandler extends EventEmitter {
} else if (document.selection) { // IE?
document.selection.empty();
}
}
clearSelection = () => {
this._currentSelection = null;
this.el.classList.remove('hide-selection');
const spans = Array.prototype.slice.call(this.el.querySelectorAll('.r6o-selection'));
if (spans) {

View File

@ -8,3 +8,11 @@
background-color:rgba(207, 207, 255, 0.63);
cursor:pointer;
}
.hide-selection::selection, .hide-selection ::selection {
background: transparent;
}
.hide-selection::-moz-selection .hide-selection ::-moz-selection{
background: transparent;
}