JSFiddle - React, Tailwind, and code Playground

by bingjie2680

HTML

<p contentedtiable="true">
    asf asfasfd <b>al asfj</b> aaf
    a sfdasfdsafdj
</p>

JavaScript

function expandRng(rng) {
    var lastIdx, leaf, endPoint,
        startContainer = rng.startContainer,
        startOffset = rng.startOffset,
        endContainer = rng.endContainer,
        endOffset = rng.endOffset;
    
    // If index based start position then resolve it
    if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) {
        lastIdx = startContainer.childNodes.length - 1;
        startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset];
        
        if (startContainer.nodeType == 3) {
            startOffset = 0;
        }
    }
    
    // If index based end position then resolve it
    if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) {
        lastIdx = endContainer.childNodes.length - 1;
        endContainer = endContainer.childNodes[endOffset > lastIdx ? lastIdx : endOffset - 1];
        
        if (endContainer.nodeType == 3) {
            endOffset = endContainer.nodeValue.length;
        }
    }
}

$(function () {
    $(body).mouseup(function () {
        
    });
});