No further help needed - fixed it.
/**
* @param {Args} args
* @param {Ctx} ctx
*/
function setCursorAtEnd ({node_id, offset}) {
const range = document.createRange();
const node = document.getElementById(node_id);
const child_node = node.childNodes[0];
// Check for child node
if (child_node) {
range.setStart(child_node.firstChild, offset); // If there is a child node, it's a span, so set the offset based on the text node
} else {
range.setStart(node, offset); // Otherwise, set the offset based on the node
}
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}