mirror of
https://github.com/dergigi/boris.git
synced 2026-01-17 05:44:24 +01:00
fix(highlights): restore FAB selection updates by listening to document selectionchange; keep clearing selection after creation
This commit is contained in:
@@ -113,6 +113,32 @@ export const useHighlightInteractions = ({
|
||||
}, 10)
|
||||
}, [onTextSelection, onClearSelection])
|
||||
|
||||
// Listen to document-level selection changes to catch keyboard/touch/ios cases
|
||||
useEffect(() => {
|
||||
const handler = () => {
|
||||
// Defer to allow DOM selection to settle
|
||||
setTimeout(() => {
|
||||
const selection = window.getSelection()
|
||||
if (!selection || selection.rangeCount === 0) {
|
||||
onClearSelection?.()
|
||||
return
|
||||
}
|
||||
|
||||
const range = selection.getRangeAt(0)
|
||||
const text = selection.toString().trim()
|
||||
|
||||
if (text.length > 0 && contentRef.current?.contains(range.commonAncestorContainer)) {
|
||||
onTextSelection?.(text)
|
||||
} else {
|
||||
onClearSelection?.()
|
||||
}
|
||||
}, 10)
|
||||
}
|
||||
|
||||
document.addEventListener('selectionchange', handler)
|
||||
return () => document.removeEventListener('selectionchange', handler)
|
||||
}, [onTextSelection, onClearSelection])
|
||||
|
||||
return { contentRef, handleSelectionEnd }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user