mirror of
https://github.com/readest/readest.git
synced 2026-11-29 19:02:28 +00:00
fix(annotator): clear a moved highlight's old anchors on the server too (#7319)
Moving a highlight's range cleared its KOReader xpointers and CrossPoint anchor as undefined, and the push drops undefined fields. When the new range then couldn't be anchored, the server kept the old range's anchors, and the next pull merged them back over the local note, so KOReader and CrossPoint kept the old range. They are now cleared as null, which the push sends, so the server forgets the old range either way, and the next session tries to anchor the new one again. From CodeRabbit's review of #7317 (outside the diff). Fails without the change: useAnnotationEditor "a moved range drops the KOReader and CrossPoint anchors of the old one" (expected undefined to be null). transform "sends anchors cleared by a moved range as null, so the server forgets them" pins that a null reaches the server record. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
045beb4d1a
commit
6ab667bd26
5 changed files with 22 additions and 12 deletions
|
|
@ -109,12 +109,14 @@ describe('useAnnotationEditor applyAnnotationRange', () => {
|
|||
|
||||
await result.current.applyAnnotationRange(range, 2, false, false);
|
||||
|
||||
// The next push anchors the new range for both readers again.
|
||||
// The next push anchors the new range for both readers again. Cleared as
|
||||
// null, not dropped, so the server forgets the old range even when the
|
||||
// new one can't be anchored.
|
||||
const [, [saved]] = h.updateBooknotes.mock.calls.at(-1) as unknown as [string, BookNote[]];
|
||||
expect(saved).toMatchObject({ cfi: 'new-cfi', text: 'edited text' });
|
||||
expect(saved!.xpointer0).toBeUndefined();
|
||||
expect(saved!.xpointer1).toBeUndefined();
|
||||
expect(saved!.crosspoint).toBeUndefined();
|
||||
expect(saved!.xpointer0).toBeNull();
|
||||
expect(saved!.xpointer1).toBeNull();
|
||||
expect(saved!.crosspoint).toBeNull();
|
||||
});
|
||||
|
||||
// #6390: a range in the footnote popup's document means nothing to the main
|
||||
|
|
|
|||
|
|
@ -85,6 +85,12 @@ describe('transformBookNoteToDB with a CrossPoint anchor', () => {
|
|||
expect('crosspoint' in pulled).toBe(false);
|
||||
expect({ ...highlight, ...pulled }.crosspoint).toEqual(highlight.crosspoint);
|
||||
});
|
||||
|
||||
it('sends anchors cleared by a moved range as null, so the server forgets them', () => {
|
||||
const moved = { ...highlight, xpointer0: null, xpointer1: null, crosspoint: null };
|
||||
const db = JSON.parse(JSON.stringify(transformBookNoteToDB(moved, 'user1')));
|
||||
expect(db).toMatchObject({ xpointer0: null, xpointer1: null, crosspoint: null });
|
||||
});
|
||||
});
|
||||
|
||||
describe('transformBookNoteToDB with xpointer fields', () => {
|
||||
|
|
|
|||
|
|
@ -83,9 +83,11 @@ export const useAnnotationEditor = ({
|
|||
cfi: newCfi,
|
||||
text: newText,
|
||||
// Anchors of the old range: the next push sets them for this one.
|
||||
xpointer0: undefined,
|
||||
xpointer1: undefined,
|
||||
crosspoint: undefined,
|
||||
// Null, not undefined, which the push would drop: the server must
|
||||
// forget the old range even if the new one can't be anchored.
|
||||
xpointer0: null,
|
||||
xpointer1: null,
|
||||
crosspoint: null,
|
||||
updatedAt: nextBooknoteStamp(existingAnnotation),
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -211,8 +211,8 @@ export interface BookNote {
|
|||
id: string;
|
||||
type: BookNoteType;
|
||||
cfi: string; // Canonicalized CFI for the note location
|
||||
xpointer0?: string; // Start XPointer for the note location
|
||||
xpointer1?: string; // End XPointer for the note location
|
||||
xpointer0?: string | null; // Start XPointer for the note location
|
||||
xpointer1?: string | null; // End XPointer for the note location
|
||||
page?: number;
|
||||
text?: string;
|
||||
style?: HighlightStyle;
|
||||
|
|
@ -237,7 +237,7 @@ export interface BookNote {
|
|||
* KOReader's. Set on a clipping a reader synced, or by a Readest app for a
|
||||
* highlight in an EPUB. See utils/crosspointClipping.
|
||||
*/
|
||||
crosspoint?: CrossPointAnchor;
|
||||
crosspoint?: CrossPointAnchor | null;
|
||||
|
||||
createdAt: number;
|
||||
updatedAt: number;
|
||||
|
|
|
|||
|
|
@ -53,8 +53,8 @@ export interface DBBookNote {
|
|||
id: string;
|
||||
type: string;
|
||||
cfi?: string;
|
||||
xpointer0?: string;
|
||||
xpointer1?: string;
|
||||
xpointer0?: string | null;
|
||||
xpointer1?: string | null;
|
||||
page?: number;
|
||||
text?: string;
|
||||
style?: string;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue