Insights refinements

This commit is contained in:
Tom Moor
2022-11-13 14:47:20 -05:00
parent 3880a956a3
commit b60c66316a
5 changed files with 71 additions and 70 deletions

View File

@@ -9,14 +9,15 @@ import useEventListener from "./useEventListener";
export default function useTextSelection() {
const [selection, setSelection] = React.useState<string>("");
const handleMouse = React.useCallback(() => {
const selection = window.getSelection();
const text = selection?.toString();
setSelection(text ?? "");
}, []);
useEventListener("mousemove", handleMouse);
useEventListener("mouseup", handleMouse);
useEventListener(
"selectionchange",
() => {
const selection = window.getSelection();
const text = selection?.toString();
setSelection(text ?? "");
},
document
);
return selection;
}