Skip to content

feat(reader): 页级笔记兜底 —— 不支持划词的格式(PDF 等)也能添加笔记 - #782

Open
jenken827 wants to merge 4 commits into
codedogQBY:mainfrom
jenken827:feat/page-level-notes
Open

jenken827 wants to merge 4 commits into
codedogQBY:mainfrom
jenken827:feat/page-level-notes

Conversation

@jenken827

Copy link
Copy Markdown

问题

添加笔记的现有入口只有"划词":选中文字 → 弹出菜单 → 高亮/添加笔记。但部分格式不支持这个流程——PDF 的选择弹窗中高亮/笔记按钮被禁用SelectionPopoverdisabled: isPdf 的格式门槛),扫描版 PDF 更是没有文字层可选。结果:这类格式的书籍完全无法添加笔记

方案:页级笔记兜底

阅读器的笔记本面板头部新增"添加页级笔记"按钮(所有格式可见):

  • 点击后打开内联笔记编辑器,锚定当前阅读位置(当前页/当前 CFI);
  • 保存后列表显示"第 N 页笔记"(N 为记录时的页码),点击笔记跳回记录时的页面
  • EPUB 同样支持(锚定为当前位置 CFI,点击跳回对应位置)。
image

实现要点

  1. 零数据库 / 零同步格式改动:复用现有"高亮 + note"存储(highlights 表,本就在同步范围内)。页级笔记 = text 为空串、cfi 为当前位置的 Highlight 行;
  2. 页码显示:PDF 等固定版式的定位是 foliate 的 fake CFI(epubcfi(/6/N),N=(页码)×2),可反向解析出页码用于列表标题(第 N 页笔记);EPUB 等流式格式的 CFI 不含页码,回退显示通用占位(下方的章节名提供上下文);
  3. 编辑器上下文适配:页级笔记创建时隐藏"选中文本"预览,改为显示"页级笔记 · 第 N 页 · 章节名";空内容的页级笔记禁止保存(避免产生列表中不可见的空行);
  4. 列表渲染兜底highlight.text 为空的条目在笔记本面板和首页笔记页显示斜体占位("页级笔记" / "第 N 页笔记"),不再渲染空引号;
  5. 选择弹窗的 isPdf 门槛保持不变(PDF 划词路径质量不稳,本 PR 不放开;页级按钮是兜底入口)。

验证

  • core 全量 584 个单元测试通过,改动文件 lint 零错误,tsc 通过;
  • 真机验证:EPUB 与 PDF 分别创建页级笔记 → 列表显示"第 N 页笔记" → 点击跳回记录时的页面(PDF 跳页、EPUB 跳位置)→ 首页笔记页占位渲染与跳转正常。

已知小瑕疵

导出笔记时,页级笔记的"引用文本"渲染为空引号(导出器尚未对空 text 做占位处理),后续可在导出器过滤。

注:本次代码修改和PR信息由AI生成

…ction

PDF (and other formats without usable text selection) could not take
notes: the selection popover's highlight/note buttons are format-gated
(disabled: isPdf), and scanned PDFs have no text layer at all.

Adds a page-level note fallback, reusing the existing highlight-with-note
storage (zero schema/sync changes):

- NotebookPanel header gains an add-note button (all formats; opens the
  inline editor anchored to the current position)
- ReaderView.handleAddPageNote captures tab.currentCfi (PDF: page-level
  fake CFI that resolves back to the page; EPUB: current location CFI),
  current page number and chapter title
- The editor shows page context instead of quoted text when the note has
  no selected text; saving an empty page-level note is disabled (it would
  be an invisible row)
- List rendering falls back to a page-note placeholder when
  highlight.text is empty (NotebookPanel + NotesPage)
- Clicking the note navigates via the existing navigateToCfi path —
  PDF fake CFIs resolve back to the recorded page

The PDF selection popover gate stays as-is (per product decision); this
button is the fallback entry.
…r labels

- Header button icon NotebookPen -> Plus (an add affordance, not edit)
- Remove the duplicated icon+label left inside the save button by the
  previous patch (rendered as two 保存 buttons)
- Page-level note labels show the page number parsed from the fixed-layout
  fake CFI ("第N页笔记"); reflowable books fall back to the generic badge
  (chapter title below provides context)
…refix

i18n resources merge all locale files into a single translation namespace
(reader.json's content is top-level, not nested under a reader key), so
t("reader.notebook.pageNoteWithPage") looked up a nonexistent path and
rendered the literal key. Use notebook.pageNoteWithPage / notebook.pageNoteBadge.
NotesPage was already on the helper and picked up the fix automatically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant