Fix annotation visibility and current chapter picker - #151
Open
q107580018 wants to merge 6 commits into
Open
Conversation
… matching Add "Sync single chapter…" to the local-book annotation menu so users can sync one WeRead chapter at a time, keeping per-session request counts low enough to stay under WeRead rate limits. The picker maps WeRead chapters to local TOC entries by title (ignoring the whole-book chapterIdx, so volume two's "第二十四章 序列2" stays chapter 24) and marks checkpointed chapters as already synced. Locating no longer runs one CREngine full-text search per underline: findText with origin=0 always scans from the viewport to the end of the book, which is what made single-chapter matching take minutes. Instead: - Extract the bounded chapter text once via getTextFromXPointers and match quotes against a whitespace-normalized flat rendering in pure Lua (paragraph breaks, spaces and full-width spaces are ignored). - Map flat byte offsets back to XPointers with a lazy getNextVisibleChar walk that stops at the furthest needed offset; never moves the viewport. - Bound fallback hits with compareXPointers instead of rendered positions, and clear the transient selection created by text extraction/search. - Fall back to whole-book search only when a chapter has no usable bounds or the walk diverges from the extracted text. Other fixes: - Normalize chapter titles byte-safely (Lua pattern classes truncate multi-byte UTF-8) and strip WeRead update suffixes like (第一更求推荐票); index normalized TOC titles for O(catalog+toc) matching (was 2.7s for 1400+ chapters). - A single-chapter pick re-locates only the picked chapter plus checkpointed chapters without saved records, so matching does not get slower as the checkpoint grows. - Add INFO-level external_annotation_perf logs (per chapter and per quote timings, quote byte length and short hash only, never full text) and performance-path specs asserting bounded chapters never call findAllText and never move the reading position.
…ocal text Two correctness fixes discovered while testing the chapter-bounded locator on device. Locate improvements: - Walk visible characters backwards from the next chapter boundary instead of forwards from the current chapter start. A TOC XPointer can name an element rather than a text position, in which case getNextVisibleChar(<heading element>) may be treated as a move past the element; the next chapter's boundary XPointer is a stable exclusive point and getPrevVisibleChar from it lands on the final visible character of the current chapter. - After mapping a quote to XPointers, read the mapped range back with getTextFromXPointers and compare its flattened text to the quote; on mismatch invalidate the walk and fall back instead of emitting a mislocated record. This also guards against paragraph-separator and punctuation-width differences. Thought popup fix: - When tapping a local underline, title the popup with the exact local underline text instead of the WeRead review abstract, which can carry nearby context that differs from the sentence shown in the overlay. - Deep-copy the tapped record's items before opening the popup so editing the popup never mutates the saved overlay records. Tests updated for the reverse walk, the mapped-range validation, and the popup title behavior.
Owner
|
这个修改将主菜单勾选状态统一为全局 建议快捷菜单也直接读取同一个全局 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明
修复划线和想法显示状态,以及“选择章节匹配”的章节定位体验:
类型
Bugfix 要求
修复前复现步骤:
修复后,勾选框反映实际显示偏好,章节选择器会定位并突出显示当前章节。
测试
bash scripts/run_lua_specs.shbash scripts/check_lua_namespace.shluacheck main.lua _meta.lua weread specKOReader integration测试说明:
非公开 WeRead API
脚本路径:
复现命令与脱敏结果:
模块结构
本 PR 未新增项目 Lua 模块,现有修改遵循
weread/lib/、weread/ui/命名空间规范。截图
本 PR 涉及菜单交互,但修改已通过 KOReader 实机验证;当前未附截图。
Checklist
settings/weread.lua、API key、cookie、token、x-wrpa-*或私人书籍内容。weread/lib/、weread/ui/命名空间规范。weread/lib/i18n.lua。scripts/中提交可独立运行、可复现的 Python 验证脚本,并填写了复现命令和脱敏结果。