The below code snippet is working well for all browsers except Microsoft Edge.
JavaScript
x
5
1
$rootScope.highlights = $window.rangy.createHighlighter();
2
$rootScope.highlights.addClassApplier($window.rangy.createClassApplier('commented-text'));
3
$rootScope.highlights.highlightSelection('commented-text');
4
$window.getSelection().collapseToStart();
5
Is there anything we need to specifically add for Edge?
Advertisement
Answer
After a lot of research, came to solution that rangy.createHighlighter() without any parameters won’t work for Edge.
You need to specify the “TextRange” additional parameter (see below).
The default is “textContent”.
JavaScript
1
2
1
$rootScope.highlights = rangy.createHighlighter(window.document, "TextRange");
2
Reference: https://github.com/timdown/rangy/wiki/Highlighter-Module