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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(docs-ui): doc float menu font size calc error (#4915)
ZhangWeicb802d531335
diff --git a/packages/core/src/shared/tools.ts b/packages/core/src/shared/tools.tsindex c79a1eb4f3..94e96949a2 100644--- a/packages/core/src/shared/tools.ts+++ b/packages/core/src/shared/tools.ts@@ -116,6 +116,15 @@ function diffObject(oneObject: IKeyValue, twoObject: IKeyValue) {* Universal tool library*/export class Tools {+ static deleteNull(obj: any) {+ for (const key in obj) {+ if (obj[key] === null || obj[key] === undefined) {+ delete obj[key];+ }+ }+ return obj;+ }+static stringAt(index: number): string {let str = '';let idx = index;diff --git a/packages/docs-ui/src/commands/commands/inline-format.command.ts b/packages/docs-ui/src/commands/commands/inline-format.command.tsindex 867b86e6de..20dc04791a 100644--- a/packages/docs-ui/src/commands/commands/inline-format.command.ts+++ b/packages/docs-ui/src/commands/commands/inline-format.command.ts@@ -475,8 +475,9 @@ export function getStyleInTextRange(const style = Tools.deepClone(defaultStyle);// Get the min font size in range.- style.fs = Math.max(...textRuns.map((t) => t?.ts?.fs ?? style.fs!));- style.fs = Number.isNaN(style.fs) ? undefined : style.fs;+ const fsArr = textRuns.map((t) => t?.ts?.fs).filter(Boolean) as number[];+ style.fs = style.fs ? Math.max(style.fs!, ...fsArr) : fsArr.length ? Math.max(...fsArr) : undefined;+ 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/float-menu.controller.ts b/packages/docs-ui/src/controllers/float-menu.controller.tsindex 2c3aa97b0c..7557b0edb4 100644--- a/packages/docs-ui/src/controllers/float-menu.controller.ts+++ b/packages/docs-ui/src/controllers/float-menu.controller.ts@@ -51,6 +51,10 @@ export class FloatMenuController extends Disposable {super();this._registerFloatMenu();this._initSelectionChange();++ this.disposeWithMe(() => {+ this._hideFloatMenu();+ });}private _registerFloatMenu() {diff --git a/packages/docs-ui/src/controllers/menu/menu.ts b/packages/docs-ui/src/controllers/menu/menu.tsindex a7f37f276f..713c311cf8 100644--- a/packages/docs-ui/src/controllers/menu/menu.ts+++ b/packages/docs-ui/src/controllers/menu/menu.ts@@ -31,6 +31,7 @@ import {NAMED_STYLE_MAP,NamedStyleType,ThemeService,+ Tools,UniverInstanceType,} from '@univerjs/core';import {@@ -1049,7 +1050,7 @@ function getFontStyleAtCursor(accessor: IAccessor) {}const curTextStyle = getStyleInTextRange(body, activeRange, {});-+ Tools.deleteNull(curTextStyle);return {ts: {...defaultTextStyle,