Skip to content

Commit 1de75a3

Browse files
committed
Drop the unreachable commentColor back-compat in PdfViewerConfig
PdfViewerConfig::fromJson() seeded all three tools from a legacy shared `commentColor` key when `tools` was absent. That branch cannot run. ConfigMgr2::init() applies the user's document as an RFC 7386 merge patch on top of the default-constructed MainConfig's toJson(), and toJson() always emits `tools`. So by the time fromJson() sees the object, `tools` is present unconditionally and the guard is always false. The branch only ever executed from a direct fromJson() call -- which is exactly what its test did, so the gate asserted the dead path rather than catching it. Nothing is lost by removing it. `commentColor` existed only in the local pdf.js-v6 commit and was never on master, so no config on disk anywhere carries it. And absent-key safety for the replacement keys is now covered better than the removed test covered it: testAbsentKeyKeepsTheCppDefaultForEveryField drops each leaf key of the defaults document in turn and reloads through a real ConfigMgr2::init(), which includes tools.*.color, tools.ink.width and tools.freetext.fontSize. The remaining `tools`-absent fallback is kept and its comment now says what it is actually for: a direct fromJson() call, not a migration. Full suite 216/216.
1 parent b099871 commit 1de75a3

2 files changed

Lines changed: 3 additions & 39 deletions

File tree

‎src/core/pdfviewerconfig.cpp‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,9 @@ void PdfViewerConfig::fromJson(const QJsonObject &p_jobj) {
2626
m_toolOptions.insert(tool, ToolOptions());
2727
}
2828

29-
// Back-compat: the shared `commentColor` shipped in this branch before the
30-
// per-tool split. Seeding all three from it stops an already-picked value
31-
// from silently resetting to yellow.
32-
const auto legacyColor = p_jobj.value(QStringLiteral("commentColor")).toString();
33-
const bool hasTools = p_jobj.value(QStringLiteral("tools")).isObject();
34-
if (!hasTools && CommentColor::isValid(legacyColor)) {
35-
for (auto it = m_toolOptions.begin(); it != m_toolOptions.end(); ++it) {
36-
it->m_color = legacyColor;
37-
}
38-
return;
39-
}
40-
41-
// Absent key keeps the C++ default, which is what makes this safe to add
42-
// without a config migration.
29+
// Absent key keeps the C++ default. In practice ConfigMgr2::init() merges the
30+
// user's document over the defaults document, so `tools` is always present by
31+
// the time this runs; the fallback matters only for a direct fromJson() call.
4332
const auto toolsObj = p_jobj.value(QStringLiteral("tools")).toObject();
4433
for (const auto &tool : toolNames()) {
4534
m_toolOptions.insert(tool, toolOptionsFromJson(tool, toolsObj.value(tool).toObject()));

‎tests/core/test_configmgr2.cpp‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,31 +1219,6 @@ void TestConfigMgr2::testPdfToolOptions_defaultsAndRoundTrips() {
12191219
QCOMPARE(pdfConfig.getToolOptions(ink).m_color, CommentColor::defaultToken());
12201220
QCOMPARE(pdfConfig.getToolOptions(ink).m_width, PdfInkAnchor::maxWidth());
12211221
}
1222-
1223-
{
1224-
// Back-compat: the shared `commentColor` this branch shipped before the
1225-
// per-tool split seeds all three, so an already-picked value does not
1226-
// silently reset to yellow.
1227-
MainConfig config(m_configMgr);
1228-
auto &pdfConfig = config.getEditorConfig().getPdfViewerConfig();
1229-
1230-
QJsonObject obj;
1231-
obj.insert(QStringLiteral("commentColor"), QStringLiteral("pink"));
1232-
pdfConfig.fromJson(obj);
1233-
for (const auto &tool : PdfViewerConfig::toolNames()) {
1234-
QCOMPARE(pdfConfig.getToolOptions(tool).m_color, QStringLiteral("pink"));
1235-
}
1236-
1237-
// `tools` wins when both are present.
1238-
QJsonObject tools;
1239-
QJsonObject inkObj;
1240-
inkObj.insert(QStringLiteral("color"), QStringLiteral("green"));
1241-
tools.insert(PdfToolOptions::inkTool(), inkObj);
1242-
obj.insert(QStringLiteral("tools"), tools);
1243-
pdfConfig.fromJson(obj);
1244-
QCOMPARE(pdfConfig.getToolOptions(PdfToolOptions::inkTool()).m_color, QStringLiteral("green"));
1245-
QCOMPARE(pdfConfig.getToolOptions(highlight).m_color, CommentColor::defaultToken());
1246-
}
12471222
}
12481223

12491224
// The Task 0 normalization table, one row per class, asserted on BOTH the

0 commit comments

Comments
 (0)