feat(annotator): show the loupe when selecting text in instant annotation, closes #3539 (#3565)

This commit is contained in:
Huang Xin
2026-03-19 22:10:33 +08:00
committed by GitHub
parent 7f62cdcab9
commit eab83c6d3f
10 changed files with 282 additions and 31 deletions
@@ -1,15 +1,18 @@
import { useEffect, useRef } from 'react';
import { BookNote } from '@/types/book';
import { useEnv } from '@/context/EnvContext';
import { useReaderStore } from '@/store/readerStore';
import { useBookDataStore } from '@/store/bookDataStore';
import { getOSPlatform } from '@/utils/misc';
import { eventDispatcher } from '@/utils/event';
import { isPointerInsideSelection, TextSelection } from '@/utils/sel';
import { isPointerInsideSelection, Point, TextSelection } from '@/utils/sel';
import { useInstantAnnotation } from './useInstantAnnotation';
export const useTextSelector = (
bookKey: string,
setSelection: React.Dispatch<React.SetStateAction<TextSelection | null>>,
setEditingAnnotation: React.Dispatch<React.SetStateAction<BookNote | null>>,
setExternalDragPoint: React.Dispatch<React.SetStateAction<Point | null>>,
getAnnotationText: (range: Range) => Promise<string>,
handleDismissPopup: () => void,
) => {
@@ -35,7 +38,13 @@ export const useTextSelector = (
handleInstantAnnotationPointerMove,
handleInstantAnnotationPointerCancel,
handleInstantAnnotationPointerUp,
} = useInstantAnnotation({ bookKey, getAnnotationText, setSelection });
} = useInstantAnnotation({
bookKey,
getAnnotationText,
setSelection,
setEditingAnnotation,
setExternalDragPoint,
});
const isValidSelection = (sel: Selection) => {
return sel && sel.toString().trim().length > 0 && sel.rangeCount > 0;
@@ -125,7 +134,6 @@ export const useTextSelector = (
stopInstantAnnotating(ev);
const handled = await handleInstantAnnotationPointerUp(doc, index, ev);
if (handled) {
isTextSelected.current = true;
return;
} else {
// If instant annotation was not created, we let the event propagate
@@ -251,6 +259,7 @@ export const useTextSelector = (
return {
isTextSelected,
isInstantAnnotating,
handleScroll,
handleTouchStart,
handleTouchMove,