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): active bg color (#5834)

Roman Sergeev909a2b8e4d6e
diff --git a/packages/docs-ui/src/controllers/menu/menu.ts b/packages/docs-ui/src/controllers/menu/menu.ts
index 762945a351..0728247943 100644
--- a/packages/docs-ui/src/controllers/menu/menu.ts
+++ b/packages/docs-ui/src/controllers/menu/menu.ts
@@ -1005,7 +1005,7 @@ export function ResetBackgroundColorMenuItemFactory(accessor: IAccessor): IMenuB
};
}
-export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string, string | undefined> {
const commandService = accessor.get(ICommandService);
const themeService = accessor.get(ThemeService);
@@ -1021,6 +1021,30 @@ export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMe
hoverable: false,
selectable: false,
},
+ value$: new Observable<string>((subscriber) => {
+ const defaultValue = DEFAULT_STYLES.bg.rgb;
+ const calc = () => {
+ const textRun = getFontStyleAtCursor(accessor);
+
+ if (!textRun) {
+ subscriber.next(defaultValue);
+ return;
+ }
+
+ const color = textRun.ts?.bg?.rgb;
+
+ subscriber.next(color ?? defaultValue);
+ };
+
+ const disposable = commandService.onCommandExecuted((c) => {
+ if (c.id === SetInlineFormatTextBackgroundColorCommand.id) {
+ calc();
+ }
+ });
+
+ calc();
+ return disposable.dispose;
+ }),
},
],
value$: new Observable<string>((subscriber) => {