timdown / rangy

A cross-browser JavaScript range and selection library.
MIT License
2.24k stars 368 forks source link

Single selection #436

Open SiriusED opened 6 years ago

SiriusED commented 6 years ago

I need to make 'rehighlighting' in the text. So basically I need remove prev highlight and create new one. But this code doesn't work, when I select text it just unselects everything, and it removes current highlight also instead of remove previous highlight and highlight new selection:

if (this.selObj) {
    this.highlighter.removeHighlights(this.highlighter.highlights);
}
this.selObj = rangy.getSelection();

this.highlighter.highlightSelection('text-highlight');
rangy.getSelection().removeAllRanges();

So basically I want to implement single lighlight selection only, I need user to make only one highlighting of the whole text in one moment. Is that supported somehow atm?