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

View File

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