Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 1x | /** * Save the current browser selection, so that it can be restored later. Returns * a callback to restore the selection. * * @returns Callback to restore the selection. */ export const saveSelection = (): (() => void) | undefined => { const selection = window?.getSelection(); Iif (!selection) return; const ranges: Range[] = []; for (let i = 0; i < selection.rangeCount; i++) ranges.push(selection.getRangeAt(i)); return () => { selection.removeAllRanges(); for (const range of ranges) selection.addRange(range); }; }; |