Skip to content

Instantly share code, notes, and snippets.

View joshuaepstein's full-sized avatar
🖥️
Coding some cool stuff

Joshua Epstein joshuaepstein

🖥️
Coding some cool stuff
View GitHub Profile
@joshuaepstein
joshuaepstein / useTextSelection.ts
Created February 12, 2024 11:24 — forked from KristofferEriksson/useTextSelection.ts
A React Typescript hook that tracks user text selections & their screen positions
import { useEffect, useState } from "react";
type UseTextSelectionReturn = {
text: string;
rects: DOMRect[];
ranges: Range[];
selection: Selection | null;
};
const getRangesFromSelection = (selection: Selection): Range[] => {