forked from akai/readest
The sidebar delete handler always removed annotations through the note bubble overlay key (`NOTE_PREFIX + cfi`), but highlights are keyed by the raw CFI. Deleting a highlight from the sidebar therefore left its overlay drawn until the book was reopened, while the popup path — which lets `wrappedFoliateView` default the value to the CFI — worked. Introduce `removeBookNoteOverlays` that mirrors the draw filters in `Annotator.tsx` and clears every overlay a BookNote can own (highlight and/or note bubble), and route the sidebar delete through it. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { HIGHLIGHT_COLOR_HEX } from '@/services/constants';
|
||||
import { DEFAULT_HIGHLIGHT_COLORS, HighlightColor } from '@/types/book';
|
||||
import { BookNote, DEFAULT_HIGHLIGHT_COLORS, HighlightColor } from '@/types/book';
|
||||
import { SystemSettings } from '@/types/settings';
|
||||
import { FoliateView, NOTE_PREFIX } from '@/types/view';
|
||||
import { Point } from '@/utils/sel';
|
||||
|
||||
export const isDefaultHighlightColor = (
|
||||
@@ -62,3 +63,26 @@ export function toParentViewportPoint(doc: Document, x: number, y: number): Poin
|
||||
const frameRect = frameElement?.getBoundingClientRect() ?? { top: 0, left: 0 };
|
||||
return { x: x + frameRect.left, y: y + frameRect.top };
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any overlays drawn for a BookNote from the given view.
|
||||
*
|
||||
* A single BookNote can have up to two overlays attached:
|
||||
* - a highlight/underline/squiggly overlay (keyed by the raw CFI)
|
||||
* - a note bubble overlay (keyed by `${NOTE_PREFIX}${cfi}`)
|
||||
*
|
||||
* The set of overlays drawn is defined by the progress-sync effect in
|
||||
* Annotator.tsx, and this helper mirrors those filters so that deleting
|
||||
* an annotation from the sidebar clears every overlay that was drawn
|
||||
* for it, not just the note bubble.
|
||||
*/
|
||||
export function removeBookNoteOverlays(view: FoliateView | null, note: BookNote): void {
|
||||
if (!view) return;
|
||||
if (note.type !== 'annotation') return;
|
||||
if (note.style) {
|
||||
view.addAnnotation({ ...note, value: note.cfi }, true);
|
||||
}
|
||||
if (note.note && note.note.trim().length > 0) {
|
||||
view.addAnnotation({ ...note, value: `${NOTE_PREFIX}${note.cfi}` }, true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user