Repository navigation
[6043] 修复长文档末尾删除图片导致全文重复排版的缺陷 - #4806
Merged
Merged
Conversation
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.
问题描述
在 Mogan STEM 中打开包含图片的文档(如
tests/mogan/stem/6043.stem),将光标移动到文档末尾并连续按下 Backspace 键删除末尾图片后,文档发生严重的排版混乱:在原第 5 页图片下方,整篇文档从头开始被重复排版了一遍,章节编号累加漂移(节编号从「1」变为「22」,小节编号变为「22.1」),总页数从 5 页跳增至 9 页,且光标异常跳回文档起始位置。根因分析
notify_remove已收缩max_typeset_child并调用progressive_reset(),冻结页面、doc_l与分块边界会被正常清空;但图片占据的空间消失后,总页数从 5 页合法下降为 4 页,命中last_page_count > 0 && nr_pages < last_page_count兜底。页数只在同一文档内容不变时可以比较,不能作为跨删除操作的单调不变式。typesetter_rep::typeset()在第一次br->typeset()和分页完成后才进入该兜底。progressive_reset()只清理渐进式累计状态,不清理本轮已经生成的l、sb、a、b;兜底随后直接再次调用br->typeset(),第二次全文输出经insert_stack/merge_stack追加到第一次输出之后。l,因而文档开头标题和正文再次出现在原页面之后;章节计数环境也在同一轮被再次执行,导致编号累加。重复盒路径及错误页数又使光标定位失效并退化为start。修复内容
src/Typeset/Bridge/typesetter.cpp&src/Typeset/Bridge/impl_typesetter.hpp:last_page_count > 0 && nr_pages < last_page_count)及last_page_count状态字段;br->typeset(),消除重复排版与章节编号漂移;notify_remove按删除区间准确收缩max_typeset_child并统一progressive_reset()。tests/Typeset/progressive_typeset_test.cpp:test_remove_at_end_legal_page_shrink_no_duplicate:验证文末删除导致合法缩页时页数正常减少、无待排版状态、唯一标题仅出现 1 次;test_remove_relative_to_progressive_frontier:分别覆盖在前沿之前、跨越前沿和在前沿之后删除节点时max_typeset_child、chunk_end及内容完整性。验证情况
gf fmt --changed-since=main:格式检查通过。xmake b progressive_typeset_test && xmake r progressive_typeset_test:13 passed, 0 failed。python3 tests/mogan/python/6043.py --verify:通过(文末删除图片后未发生全文重复排版,NCC=0.253)。