fix: v0.10.6 —— 修复代码框/表格之后内容被吞进去导致导出卡死

根因
- 插入 QTextFrame(代码块)或 QTextTable(表格)之后,光标被设到
  frame->lastPosition()——这个位置仍然在框内部,于是后续所有内容
  都被插进了这个框/单元格里,一层层嵌套
- 复杂文档(有多张表、多个代码块)嵌套后文档高度从 1.3 万爆到 12 万,
  分页时几乎算不完,表现就是点导出直接卡住

修复
- 定位到 lastPosition() + 1(框外的位置)再继续写
- 实测同一份 11KB 报告:修复前文档高度 120137、导出超时;
  修复后 13664、14 页 A4,1 秒内完成

顺带
- 之前版本里代码块/表格后面的内容排版其实也是错的(被塞进框里),
  这次一并修正
- 版本 0.10.6
This commit is contained in:
2026-10-22 19:07:01 +08:00
parent fc6b52cd32
commit 4f5fd0eeaa
2 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
TEMPLATE = app TEMPLATE = app
TARGET = VoiletMark TARGET = VoiletMark
VERSION = 0.10.5 VERSION = 0.10.6
QT += core gui widgets QT += core gui widgets
+5 -3
View File
@@ -276,9 +276,10 @@ void Renderer::renderCodeBlock(const QStringList &lines, const QString &info)
frameCursor.insertText(QStringLiteral(" "), format); frameCursor.insertText(QStringLiteral(" "), format);
} }
// 光标挪到边框外面,后面的内容接着写 // 光标挪到边框外面:lastPosition() 还在框内,+1 才是框后面的位置,
// 否则后续内容会一层层嵌进这个框里,排版高度爆掉、导出时卡死。
m_cursor = QTextCursor(m_document); m_cursor = QTextCursor(m_document);
m_cursor.setPosition(frame->lastPosition()); m_cursor.setPosition(qMin(frame->lastPosition() + 1, m_document->characterCount() - 1));
} }
QColor Renderer::tokenColor(CodeHighlight::Token token) const QColor Renderer::tokenColor(CodeHighlight::Token token) const
@@ -373,8 +374,9 @@ void Renderer::renderTable(const QStringList &rows, const QString &separator)
} }
} }
// 同样要跨过表格边界,否则后面的内容会塞进最后一个单元格
m_cursor = QTextCursor(m_document); m_cursor = QTextCursor(m_document);
m_cursor.setPosition(table->lastPosition()); m_cursor.setPosition(qMin(table->lastPosition() + 1, m_document->characterCount() - 1));
} }
void Renderer::renderRule() void Renderer::renderRule()