rangy
rangy copied to clipboard
Highlighter module `highlightSelection()` function overrides selection option when provided
When using the Highlighter module, if the function highlightSelection
function is called with the selection option - e.g.
highlighter = rangy.createHighlighter(document); highlighter.highlightSelection('highlight', { selection: currentSelection });
the currentSelection
object will be overridden by the api.getSelection(this.doc)
call in the highlightSelection
function (rangy-highlighter.js line 463).
The api.getSelection(this.doc)
call only needs to happen if the selection option is empty. Currently, this is being called every time to create the default options to be used in the createOptions
function, in which it will be tested if there are any options.
In conclusion: if you call highlightSelection
with the selection option, the selection option will be ignored.
From my perspective, this can be solved by changing the createOptions
defaultOptions argument to be lazy evaluated (only if it's needed), or by changing the highlightSelection
function to not use the createdOptions
.
I stumbled upon the same problem and would love to read what's the correct change I would need to make to the highlightSeleciton function in order to make it work.