This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user