Skip to content
Advertisement

Rangy selection not working on Microsoft Edge

The below code snippet is working well for all browsers except Microsoft Edge.

$rootScope.highlights = $window.rangy.createHighlighter();
$rootScope.highlights.addClassApplier($window.rangy.createClassApplier('commented-text'));
$rootScope.highlights.highlightSelection('commented-text');
$window.getSelection().collapseToStart();

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”.

$rootScope.highlights = rangy.createHighlighter(window.document, "TextRange");

Reference: https://github.com/timdown/rangy/wiki/Highlighter-Module

Advertisement