feat(note): page background templates (rnote-style)
Some checks failed
CI / Windows build (push) Has been cancelled

A blank note can show a page-background template painted behind the
ink, picked from the toolbar and persisted per notebook.

- NoteBackground: blank / dots / ruled / grid / cornell, drawn in
  page space (scales with zoom), subtle grey. Cornell = left margin +
  bottom summary rule over a ruled body.
- Stored as the enum name in the notebook sidecar (back-compat:
  missing/unknown -> blank), saved/loaded via SidecarRepository so it
  restores on reopen.
- Picker added to the note tool palette.

PDF backgrounds skipped (PDFs have their own page content). analyze
clean, 386 tests green.
This commit is contained in:
2026-06-24 23:47:29 +08:00
parent 46589a4c87
commit c800295c12
6 changed files with 303 additions and 2 deletions

View File

@@ -145,6 +145,10 @@ class SidecarRepository {
/// The standalone-notebook title loaded from the sidecar, or null.
String? get loadedTitle => _sidecar.title;
/// The page-background template name loaded from the sidecar, or null
/// (missing → blank, decoded by the editor).
String? get loadedBackground => _sidecar.background;
// ── Mutations (synchronous in-memory update + debounced atomic write) ──────
/// Replace the standalone-notebook title and schedule a save. No-op if the
@@ -154,6 +158,13 @@ class SidecarRepository {
_replace(title: title);
}
/// Replace the page-background template (a [NoteBackground] enum name) and
/// schedule a save. No-op if unchanged.
void scheduleBackgroundSave(String background) {
if (_sidecar.background == background) return;
_replace(background: background);
}
/// Replace the handwriting-OCR search text and schedule a save (Phase 6
/// search index). No-op if unchanged.
void scheduleOcrTextSave(String? ocrText) {
@@ -266,6 +277,7 @@ class SidecarRepository {
List<SidecarScratchLink>? scratchLinks,
String? ocrText,
bool clearOcrText = false,
String? background,
}) {
if (_disposed) return;
_sidecar = BadnoteSidecar(
@@ -282,6 +294,7 @@ class SidecarRepository {
bookmarks: _sidecar.bookmarks,
scratchLinks: scratchLinks ?? _sidecar.scratchLinks,
ocrText: clearOcrText ? null : (ocrText ?? _sidecar.ocrText),
background: background ?? _sidecar.background,
);
_timer?.cancel();
_timer = Timer(_debounce, () {