// Save the selection// Return a `Range` instance if there is a selected textconst save = function () {const selection = window.getSelection();return selection.rangeCount === 0 ? null : selection.getRangeAt(0);};// Restore the selection// `range` is a `Range` objectconst restore = function (range) {const selection = window.getSelection();selection.removeAllRanges();selection.addRange(range);};