JSFiddle - React, Tailwind, and code Playground

HTML

<script src="http://zp.php5.cz/rangy-core.js"></script>
<script src="http://zp.php5.cz/rangy-selectionsaverestore.js"></script>
<div id="contenteditable" contenteditable="true"></div>

CSS

#contenteditable { width:300px;height:100px;border:1px solid red }

JavaScript

var saved_selection = false;

$('#contenteditable').bind('keypress mouseup', function(e){
  $(this).find('.rangySelectionBoundary').remove();
  saved_selection = rangy.saveSelection();
});