Pin notes to passages in a PDF, and put the notes control with the rest
The panel beside a PDF is for notes about the document; a note that belongs to one paragraph is a different thing, and one that has to begin "on page 14, third paragraph" has already lost its place. Click Randnotiz, click the passage, write. Pins ride in the same per-page overlay as the drawings, in PDF points, so one stays on its sentence at every zoom and in the exported file. Living outside the note body has consequences that each needed handling: nothing else would index them for search, so the viewer feeds them in with their page numbers; clearing a page's ink must not take them; and "is this overlay empty?" was answered by counting strokes — in the client *and* independently in the server, so an overlay holding only pinned notes was stored as NULL and lost every note on it. They are stamped into the annotated export as a numbered marker plus a box of text, on whichever side of the pin has room. Standard PDF fonts are Latin-1, so characters outside it are replaced rather than failing the whole export. The Notizen control moves into the viewer's toolbar. A second row for one button cost reading height on every screen and put one of the document's controls somewhere none of the others were. On a phone, where the viewer is not on screen while the notes are, the way back sits in the panel. Renaming a separator no longer shifts the row: the two rules always share what is left over equally and the middle keeps one width in both states. 215 unit tests, 206 browser checks across eleven suites. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2cee00e38e
commit
6438648313
16 files changed
+1228
-170
No files matched your search
+38
-15
@@ -23,6 +23,8 @@ interface IndexEntry {
|
||||
raw: string;
|
||||
/** Text from an attached document, kept apart from what the user typed. */
|
||||
attachedRaw: string;
|
||||
/** Notes pinned to spots in an attached document. */
|
||||
pinnedRaw: string;
|
||||
}
|
||||
|
||||
const _index = new Map<string, IndexEntry>();
|
||||
@@ -68,30 +70,45 @@ export function contentToText(raw: string | null | undefined): string {
|
||||
* half.
|
||||
*/
|
||||
export function setEntry(id: string, title: string, content?: string | null, attached?: string | null): void {
|
||||
const existing = _index.get(id);
|
||||
const raw = contentToText(content);
|
||||
const attachedRaw = attached === undefined ? (_index.get(id)?.attachedRaw ?? "") : (attached ?? "");
|
||||
const attachedRaw = attached === undefined ? (existing?.attachedRaw ?? "") : (attached ?? "");
|
||||
const pinnedRaw = existing?.pinnedRaw ?? "";
|
||||
_index.set(id, {
|
||||
title: normalize(title),
|
||||
text: normalize(`${raw} ${attachedRaw}`),
|
||||
text: normalize(`${raw} ${attachedRaw} ${pinnedRaw}`),
|
||||
raw,
|
||||
attachedRaw,
|
||||
pinnedRaw,
|
||||
});
|
||||
}
|
||||
|
||||
/** Replaces one of the three halves, leaving the other two alone. */
|
||||
function setPart(id: string, title: string, part: "attachedRaw" | "pinnedRaw", value: string): void {
|
||||
const existing = _index.get(id) ?? { raw: "", attachedRaw: "", pinnedRaw: "", title: "", text: "" };
|
||||
const next = { ...existing, [part]: value };
|
||||
_index.set(id, {
|
||||
title: normalize(title),
|
||||
text: normalize(`${next.raw} ${next.attachedRaw} ${next.pinnedRaw}`),
|
||||
raw: next.raw,
|
||||
attachedRaw: next.attachedRaw,
|
||||
pinnedRaw: next.pinnedRaw,
|
||||
});
|
||||
}
|
||||
|
||||
/** Replaces only the attached document's text, leaving what the user wrote. */
|
||||
export function setAttachedText(id: string, title: string, attached: string): void {
|
||||
const existing = _index.get(id);
|
||||
setEntry(id, title, null, attached);
|
||||
// setEntry with null content would blank the written half; restore it.
|
||||
if (existing) {
|
||||
_index.set(id, {
|
||||
title: normalize(title),
|
||||
text: normalize(`${existing.raw} ${attached}`),
|
||||
raw: existing.raw,
|
||||
attachedRaw: attached,
|
||||
});
|
||||
}
|
||||
}
|
||||
export const setAttachedText = (id: string, title: string, attached: string): void =>
|
||||
setPart(id, title, "attachedRaw", attached);
|
||||
|
||||
/**
|
||||
* Replaces only the notes pinned into an attached document.
|
||||
*
|
||||
* These live in the page overlay rather than in the note body, so nothing else
|
||||
* puts them in the index — and a note you wrote onto page 14 that cannot be
|
||||
* searched for is a note you will not find again.
|
||||
*/
|
||||
export const setPinnedText = (id: string, title: string, pinned: string): void =>
|
||||
setPart(id, title, "pinnedRaw", pinned);
|
||||
|
||||
export function removeEntry(id: string): void {
|
||||
_index.delete(id);
|
||||
@@ -169,6 +186,12 @@ function snippetFor(entry: IndexEntry, terms: string[], radius = 60): string {
|
||||
|
||||
let text = entry.raw;
|
||||
let at = firstHit(text);
|
||||
// A pinned note is short and was written deliberately, so it outranks the
|
||||
// document's own text as the excerpt to show.
|
||||
if (at === -1 && entry.pinnedRaw) {
|
||||
text = entry.pinnedRaw;
|
||||
at = firstHit(text);
|
||||
}
|
||||
if (at === -1 && entry.attachedRaw) {
|
||||
text = entry.attachedRaw;
|
||||
at = firstHit(text);
|
||||
|
||||
Reference in new issue
Block a user