1

I need to get the highlighted/selected text from Angular Summernote Editor, but I'm getting troubles (I think because of context) with IE (11) and FF (Quantum).

I can get it through window.getSelection().toString() at console, but when I use it (or the angular way $window.getSelection().toString()) at code, I get nothing in IE and FF.

I've tried with timeout, with document.getSelection(), with document.selection (which throws an exception because selection is null or undefined), activeElement, selectionStart, etc.

I think somewhere in Angular I lost the context of which window am I at, but I don't know why because it works in Chrome.

Also, I've tried with the editor.createRange from plugin, but it doesn't gave me the expected result.

Here's my code:

HTML:

<summernote id="summernote" config="model.comment.summernoteOptions" on-paste="paste(evt)" on-change="change(contents)" ng-model="model.comment.selected.valueTmp"></summernote>

General controller:

$scope.paste = function (evt) {
  $scope.model.comment.normalizeDom(evt);
};

Specific controller:

this.normalizeDom = function (evt) {
  var selected = $window.getSelection().toString();

  console.log(selected);
};
Andrés Marotta
  • 315
  • 3
  • 15

0 Answers0