From 8adab112111bf9b6311f7ea24b92b63fd113e309 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 27 May 2026 06:24:09 +0800 Subject: [PATCH] Unwrap `fill` with single part in `cleanDoc` (#13350) --- src/document/utilities/index.js | 11 +++++++++-- .../integration/__tests__/doc-utilities-clean-doc.js | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/document/utilities/index.js b/src/document/utilities/index.js index aee762e74..ab36b12f9 100644 --- a/src/document/utilities/index.js +++ b/src/document/utilities/index.js @@ -266,11 +266,18 @@ function stripTrailingHardline(doc) { function cleanDocFn(doc) { switch (getDocType(doc)) { - case DOC_TYPE_FILL: - if (doc.parts.every((part) => part === "")) { + case DOC_TYPE_FILL: { + const { parts } = doc; + + if (parts.every((part) => part === "")) { return ""; } + if (parts.length === 1) { + return parts[0]; + } + break; + } case DOC_TYPE_GROUP: if (!doc.contents && !doc.id && !doc.break && !doc.expandedStates) { return ""; diff --git a/tests/integration/__tests__/doc-utilities-clean-doc.js b/tests/integration/__tests__/doc-utilities-clean-doc.js index f7c933ad9..e990a5b6f 100644 --- a/tests/integration/__tests__/doc-utilities-clean-doc.js +++ b/tests/integration/__tests__/doc-utilities-clean-doc.js @@ -14,7 +14,7 @@ describe("cleanDoc", () => { [ "fill", [fill([""]), fill([]), fill(["1"]), fill(["2", line, "3"])], - [fill(["1"]), fill(["2", line, "3"])], + ["1", fill(["2", line, "3"])], ], ["nested group", group(group("_")), group("_")], [