fixCodePointsInRange = (range) => {
  const start = charsToCodePoints({ node: range.startContainer, position: range.startOffset });
  const end = charsToCodePoints({ node: range.endContainer, position: range.endOffset });

  range.setStart(range.startContainer, start.position);
  range.setEnd(range.endContainer, end.position);

  return range;
}
Fix Range start/end offsets to code points count instead of chars count
Alters given range
@param {Range} range
@return {Range} the same range