From 8ad4fae1cf9193227369381bff350124cdaced6c Mon Sep 17 00:00:00 2001 From: Oleksandr Danylchenko Date: Thu, 21 Nov 2024 18:19:43 +0200 Subject: [PATCH] Simplified `getAnnotationBounds` --- .../src/state/TextAnnotationStore.ts | 2 +- .../text-annotator/src/state/TextAnnotatorState.ts | 14 ++------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/packages/text-annotator/src/state/TextAnnotationStore.ts b/packages/text-annotator/src/state/TextAnnotationStore.ts index da5b5fdc..185f0154 100644 --- a/packages/text-annotator/src/state/TextAnnotationStore.ts +++ b/packages/text-annotator/src/state/TextAnnotationStore.ts @@ -13,7 +13,7 @@ export interface TextAnnotationStore getAnnotationRects(id: string): DOMRect[]; - getAnnotationBounds(id: string, hintX?: number, hintY?: number, buffer?: number): DOMRect | undefined; + getAnnotationBounds(id: string): DOMRect | undefined; getAnnotationRects(id: string): DOMRect[]; diff --git a/packages/text-annotator/src/state/TextAnnotatorState.ts b/packages/text-annotator/src/state/TextAnnotatorState.ts index e4b74775..b2168c3d 100644 --- a/packages/text-annotator/src/state/TextAnnotatorState.ts +++ b/packages/text-annotator/src/state/TextAnnotatorState.ts @@ -114,19 +114,9 @@ export const createTextAnnotatorState = { + const getAnnotationBounds = (id: string): DOMRect | undefined => { const rects = tree.getAnnotationRects(id); - if (rects.length === 0) return; - - if (x && y) { - const match = rects.find(({ top, right, bottom, left }) => - x >= left - buffer && x <= right + buffer && y >= top - buffer && y <= bottom + buffer); - - // Preferred bounds: the rectangle - if (match) return match; - } - - return tree.getAnnotationBounds(id); + return rects.length > 0 ? tree.getAnnotationBounds(id) : undefined; } const getIntersecting = (