Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(docs-ui): float-menu and heading space (#4914)

ZhangWei1d626623c0a1
diff --git a/packages/core/src/types/const/const.ts b/packages/core/src/types/const/const.ts
index 83b834ca5e..4fd5789b31 100644
--- a/packages/core/src/types/const/const.ts
+++ b/packages/core/src/types/const/const.ts
@@ -191,13 +191,15 @@ export const NAMED_STYLE_MAP: Record<NamedStyleType, Nullable<ITextStyle>> = {
[NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED]: null,
};
+const BOTTOM_P = 4;
+
export const NAMED_STYLE_SPACE_MAP: Record<NamedStyleType, Nullable<IParagraphStyle>> = {
[NamedStyleType.HEADING_1]: {
spaceAbove: {
v: 20,
},
spaceBelow: {
- v: 6,
+ v: 6 + BOTTOM_P,
},
},
[NamedStyleType.HEADING_2]: {
@@ -205,31 +207,31 @@ export const NAMED_STYLE_SPACE_MAP: Record<NamedStyleType, Nullable<IParagraphSt
v: 18,
},
spaceBelow: {
- v: 6,
+ v: 6 + BOTTOM_P,
},
},
[NamedStyleType.HEADING_3]: {
spaceAbove: {
- v: 18,
+ v: 16,
},
spaceBelow: {
- v: 6,
+ v: 6 + BOTTOM_P,
},
},
[NamedStyleType.HEADING_4]: {
spaceAbove: {
- v: 16,
+ v: 14,
},
spaceBelow: {
- v: 4,
+ v: 4 + BOTTOM_P,
},
},
[NamedStyleType.HEADING_5]: {
spaceAbove: {
- v: 14,
+ v: 12,
},
spaceBelow: {
- v: 4,
+ v: 4 + BOTTOM_P,
},
},
[NamedStyleType.NORMAL_TEXT]: {
@@ -245,7 +247,7 @@ export const NAMED_STYLE_SPACE_MAP: Record<NamedStyleType, Nullable<IParagraphSt
v: 0,
},
spaceBelow: {
- v: 3,
+ v: 3 + BOTTOM_P,
},
},
[NamedStyleType.SUBTITLE]: {
diff --git a/packages/docs-ui/src/commands/commands/inline-format.command.ts b/packages/docs-ui/src/commands/commands/inline-format.command.ts
index f1d8e69d52..867b86e6de 100644
--- a/packages/docs-ui/src/commands/commands/inline-format.command.ts
+++ b/packages/docs-ui/src/commands/commands/inline-format.command.ts
@@ -475,7 +475,8 @@ export function getStyleInTextRange(
const style = Tools.deepClone(defaultStyle);
// Get the min font size in range.
- style.fs = Math.max(style.fs!, ...textRuns.map((t) => t?.ts?.fs ?? style.fs!));
+ style.fs = Math.max(...textRuns.map((t) => t?.ts?.fs ?? style.fs!));
+ style.fs = Number.isNaN(style.fs) ? undefined : style.fs;
style.ff = textRuns.find((t) => t.ts?.ff != null)?.ts?.ff ?? style.ff;
style.it = textRuns.length && textRuns.every((t) => t.ts?.it === BooleanNumber.TRUE) ? BooleanNumber.TRUE : BooleanNumber.FALSE;
style.bl = textRuns.length && textRuns.every((t) => t.ts?.bl === BooleanNumber.TRUE) ? BooleanNumber.TRUE : BooleanNumber.FALSE;
diff --git a/packages/docs-ui/src/controllers/menu/menu.ts b/packages/docs-ui/src/controllers/menu/menu.ts
index 89128af2ed..a7f37f276f 100644
--- a/packages/docs-ui/src/controllers/menu/menu.ts
+++ b/packages/docs-ui/src/controllers/menu/menu.ts
@@ -1048,10 +1048,11 @@ function getFontStyleAtCursor(accessor: IAccessor) {
};
}
- const curTextStyle = getStyleInTextRange(body, activeRange, defaultTextStyle);
+ const curTextStyle = getStyleInTextRange(body, activeRange, {});
return {
ts: {
+ ...defaultTextStyle,
...namedStyle,
...curTextStyle,
...cacheStyle,