refactor(reader): 重构高亮选区绘制架构,对齐 WXRead 实现方案

- 移除 RDEPUBSelectableTextView,改用原生 UITextView
- 新增 NSAttributedString 自定义属性(com.rdreader.highlight/underline)注入高亮
- RDEPUBTextPageRenderView 统一绘制高亮背景、文字和选区
- RDEPUBTextSelectionController 精简,选区矩形传递给 RenderView 绘制
- 新增高亮选区复刻 WXRead 实现方案文档
- UI 测试适配新架构

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-06-01 20:57:27 +08:00
co-authored by Claude Opus 4.7
parent 948004eed1
commit 70133e4e6e
13 changed files with 801 additions and 510 deletions
@@ -83,7 +83,7 @@ extension RDEPUBReaderController: RDEPUBTextContentViewDelegate {
updateCurrentSelection(nil)
return
}
updateCurrentSelection(normalizedTextSelection(selection))
updateCurrentSelection(selection)
}
///
@@ -92,35 +92,10 @@ extension RDEPUBReaderController: RDEPUBTextContentViewDelegate {
didRequestSelectionAction action: RDEPUBAnnotationMenuAction,
selection: RDEPUBSelection?
) {
let normalizedSelection = selection.flatMap(normalizedTextSelection)
handleSelectionMenuAction(action, selection: normalizedSelection ?? currentSelection)
handleSelectionMenuAction(action, selection: selection ?? currentSelection)
contentView.clearSelection()
}
///
private func normalizedTextSelection(_ selection: RDEPUBSelection) -> RDEPUBSelection? {
guard let textBook,
let chapterData = textBook.chapterData(for: selection.location.href) else {
return scopedSelection(selection, relativeToSpineIndex: nil)
}
guard let payload = RDEPUBTextOffsetRangeInfo.decode(from: selection.rangeInfo) else {
return scopedSelection(selection, relativeToSpineIndex: nil)
}
let contentLength = max(chapterData.attributedContent.length, 1)
let lastInclusiveOffset = max(contentLength - 1, 1)
let start = max(0, min(payload.start, lastInclusiveOffset))
let endExclusive = max(start + 1, min(payload.end, contentLength))
let absoluteRange = NSRange(location: start, length: endExclusive - start)
let location = chapterData.location(for: absoluteRange, bookIdentifier: currentBookIdentifier)
return RDEPUBSelection(
bookIdentifier: currentBookIdentifier,
location: location,
text: selection.text,
rangeInfo: selection.rangeInfo,
createdAt: selection.createdAt
)
}
/// EPUB
func pageNumber(for location: RDEPUBLocation) -> Int? {