After inserting html into contenteditable div, position cursor after insert

I can insert html into a contenteditable div just fine using this code:

function insertHtmlAtCursor(html) {
    let selection, range, node;
    selection = window.getSelection();
    if (selection.getRangeAt && selection.rangeCount) {
        range = window.getSelection().getRangeAt(0);
        node = range.createContextualFragment(html);
        range.insertNode(node);
    }
}

However, afterwards the cursor is placed within the inserted html. Instead I need it to be positioned just after the inserted html. Any ideas?