Link the margin notes from the notes, and let them be hidden
The linking went the wrong way round. A remark in the margin is short by design; when there is more to say about that passage it belongs in the notes beside the document — and it has to be possible to say *which* passage. So the pins are offered to the editor's `@` menu exactly like notes and notebooks are, labelled with their page, and following one scrolls the document to the spot and opens the remark. Pins are unhidden first: a link leading to something invisible would read as broken. A pin link is the same node with kind "pin", and is deliberately kept out of the links reported to the server. Its target is a marker inside this note's own overlay, so no note has that id, and reporting it would fill the backlink table with rows matching nothing. They can also be hidden altogether. Reading a document as it was printed is a normal thing to want; the toolbar takes the markers and the column away together and the page takes the width back. The other direction — making a note out of a remark — is removed, along with its picker and the pin's noteId: 357 lines fewer than before. The unmount flush it turned up stays, since a drawing save was genuinely being dropped by navigating away inside its debounce. 218 unit tests, 231 browser checks across eleven suites. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
502aecfc92
commit
4c1b632029
13 files changed
+239
-484
No files matched your search
@@ -181,3 +181,42 @@ describe("docToText", () => {
|
||||
expect(docToText(doc, 50).length).toBeLessThanOrEqual(50);
|
||||
});
|
||||
});
|
||||
|
||||
describe("links to a spot in a PDF", () => {
|
||||
/* They use the same node with kind "pin", but the target is a marker inside
|
||||
* this note's own overlay — not another note. Reporting one as a note link
|
||||
* would fill the backlink table with ids that match nothing at all. */
|
||||
const doc = {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [
|
||||
{ type: "noteLink", attrs: { noteId: "pin-abc", label: "S. 3", kind: "pin" } },
|
||||
{ type: "noteLink", attrs: { noteId: "note-1", label: "Andere Notiz", kind: "note" } },
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
it("are left out of the links reported to the server", () => {
|
||||
expect(extractNoteLinks(doc)).toEqual(["note-1"]);
|
||||
});
|
||||
|
||||
it("do not stop the real links in the same paragraph being reported", () => {
|
||||
expect(extractNoteLinks(doc)).toContain("note-1");
|
||||
});
|
||||
|
||||
it("are left out even when they are the only links there are", () => {
|
||||
const onlyPins = {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [{ type: "noteLink", attrs: { noteId: "pin-x", label: "S. 1", kind: "pin" } }],
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(extractNoteLinks(onlyPins)).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -117,6 +117,10 @@ function walk(node: DocNode | undefined | null, visit: (n: DocNode) => void): vo
|
||||
export function extractNoteLinks(doc: DocNode, selfId?: string): string[] {
|
||||
const ids = new Set<string>();
|
||||
walk(doc, (n) => {
|
||||
// A link to a spot in a PDF uses the same node with kind "pin", but its
|
||||
// target is a marker inside this note's own overlay, not another note.
|
||||
// Reporting it would fill the backlink table with ids that match nothing.
|
||||
if (n.attrs?.kind === "pin") return;
|
||||
if (n.type === "noteLink" && n.attrs?.noteId && n.attrs.noteId !== selfId) ids.add(n.attrs.noteId);
|
||||
});
|
||||
return [...ids];
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
/**
|
||||
* Note links — type `@` to reference another note or notebook.
|
||||
* Note links — type `@` to reference another note, a notebook, or, inside a PDF,
|
||||
* one of the notes pinned to its pages.
|
||||
*
|
||||
* A link is an atomic inline node carrying the target's id, so it survives
|
||||
* renames: the label is refreshed from the current title on render, and the id
|
||||
* is what the backlink index is built from.
|
||||
* is what the backlink index is built from. A `pin` link is deliberately left
|
||||
* out of that index — its target is a marker in the note's own overlay, so no
|
||||
* note has that id.
|
||||
*/
|
||||
|
||||
import { Node, mergeAttributes } from "@tiptap/core";
|
||||
@@ -68,7 +71,7 @@ export const NoteLink = Node.create({
|
||||
href: "#",
|
||||
title: node.attrs.label,
|
||||
}),
|
||||
`${node.attrs.kind === "notebook" ? "📓" : "📝"} ${node.attrs.label}`,
|
||||
`${{ notebook: "📓", pin: "📌" }[node.attrs.kind] || "📝"} ${node.attrs.label}`,
|
||||
];
|
||||
},
|
||||
|
||||
|
||||
Reference in new issue
Block a user