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): stabilize table paragraph menus (#7073)

Univerd3051d070fab
diff --git a/packages/docs-ui/src/commands/commands/__tests__/inline-format.command.spec.ts b/packages/docs-ui/src/commands/commands/__tests__/inline-format.command.spec.ts
index b11079d6c9..c188584666 100644
--- a/packages/docs-ui/src/commands/commands/__tests__/inline-format.command.spec.ts
+++ b/packages/docs-ui/src/commands/commands/__tests__/inline-format.command.spec.ts
@@ -19,6 +19,7 @@ import { BooleanNumber, DOC_RANGE_TYPE, ICommandService, IUniverInstanceService,
import { DocSelectionManagerService, RichTextEditingMutation, SetTextSelectionsOperation } from '@univerjs/docs';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import {
+ ResetInlineFormatTextColorCommand,
SetInlineFormatBoldCommand,
SetInlineFormatCommand,
SetInlineFormatFontFamilyCommand,
@@ -59,6 +60,7 @@ describe('Test inline format commands', () => {
commandService = get(ICommandService);
commandService.registerCommand(SetInlineFormatCommand);
+ commandService.registerCommand(ResetInlineFormatTextColorCommand);
commandService.registerCommand(SetTextSelectionsOperation);
commandService.registerCommand(RichTextEditingMutation as unknown as ICommand);
@@ -298,5 +300,29 @@ describe('Test inline format commands', () => {
rgb: '#000000',
});
});
+
+ it('Should reset text color in selected ranges', async () => {
+ await commandService.executeCommand(SetInlineFormatCommand.id, {
+ segmentId: '',
+ preCommandId: SetInlineFormatTextColorCommand.id,
+ value: '#123456',
+ });
+
+ await commandService.executeCommand(ResetInlineFormatTextColorCommand.id);
+
+ expect(getFormatValueAt('cl', 1)).toStrictEqual({
+ rgb: null,
+ });
+
+ await commandService.executeCommand(UndoCommand.id);
+ expect(getFormatValueAt('cl', 1)).toStrictEqual({
+ rgb: '#123456',
+ });
+
+ await commandService.executeCommand(RedoCommand.id);
+ expect(getFormatValueAt('cl', 1)).toStrictEqual({
+ rgb: null,
+ });
+ });
});
});
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 3d500f5353..45b3e6e647 100644
--- a/packages/docs-ui/src/commands/commands/inline-format.command.ts
+++ b/packages/docs-ui/src/commands/commands/inline-format.command.ts
@@ -198,6 +198,21 @@ export const SetInlineFormatTextColorCommand: ICommand = {
},
};
+const ResetInlineFormatTextColorCommandId = 'doc.command.reset-inline-format-text-color';
+export const ResetInlineFormatTextColorCommand: ICommand = {
+ id: ResetInlineFormatTextColorCommandId,
+ type: CommandType.COMMAND,
+ handler: async (accessor, params) => {
+ const commandService = accessor.get(ICommandService);
+
+ return handleInlineFormat(
+ ResetInlineFormatTextColorCommandId,
+ params,
+ commandService
+ );
+ },
+};
+
const SetInlineFormatTextFillCommandId = 'doc.command.set-inline-format-text-fill';
export const SetInlineFormatTextFillCommand: ICommand = {
id: SetInlineFormatTextFillCommandId,
@@ -251,6 +266,7 @@ const COMMAND_ID_TO_FORMAT_KEY_MAP: Record<string, keyof IStyleBase> = {
[SetInlineFormatFontSizeCommand.id]: 'fs',
[SetInlineFormatFontFamilyCommand.id]: 'ff',
[SetInlineFormatTextColorCommand.id]: 'cl',
+ [ResetInlineFormatTextColorCommand.id]: 'cl',
[SetInlineFormatTextBackgroundColorCommand.id]: 'bg',
[ResetInlineFormatTextBackgroundColorCommand.id]: 'bg',
[SetInlineFormatSubscriptCommand.id]: 'va',
@@ -337,6 +353,7 @@ export const SetInlineFormatCommand: ICommand<ISetInlineFormatCommandParams> = {
break;
}
+ case ResetInlineFormatTextColorCommand.id:
case ResetInlineFormatTextBackgroundColorCommand.id: {
formatValue = {
rgb: null,
diff --git a/packages/docs-ui/src/components/paragraph-menu/__tests__/paragraph-menu.spec.ts b/packages/docs-ui/src/components/paragraph-menu/__tests__/paragraph-menu.spec.ts
index 9ccde808b8..aa55f74938 100644
--- a/packages/docs-ui/src/components/paragraph-menu/__tests__/paragraph-menu.spec.ts
+++ b/packages/docs-ui/src/components/paragraph-menu/__tests__/paragraph-menu.spec.ts
@@ -21,7 +21,7 @@ import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { afterEach, describe, expect, it, vi } from 'vitest';
import * as paragraphMenu from '..';
-import { createParagraphMenuHoverOpenScheduler, getParagraphFormattingRange, getParagraphMenuActiveHeadingCommandId, getParagraphMenuCommand, getParagraphMenuCommandTargetRange, getParagraphMenuHiddenHeadingCommandIds, getParagraphMenuHiddenItemIds, getParagraphMenuIconSizeClass, getParagraphMenuPopupDirection, getParagraphMenuResolvedCommand, getParagraphMenuTargetRange, isEmptyParagraphMenuTarget, PARAGRAPH_MENU_HOVER_OPEN_DELAY, shouldShowParagraphSettingMenu, shouldUseInsertBelowRange } from '..';
+import { createParagraphMenuHoverOpenScheduler, getParagraphFormattingRange, getParagraphMenuActiveHeadingCommandId, getParagraphMenuCommand, getParagraphMenuCommandTargetRange, getParagraphMenuHiddenHeadingCommandIds, getParagraphMenuHiddenItemIds, getParagraphMenuIconSizeClass, getParagraphMenuPopupDirection, getParagraphMenuResolvedCommand, getParagraphMenuTargetRange, isEmptyParagraphMenuTarget, PARAGRAPH_MENU_HOVER_OPEN_DELAY, setParagraphMenuInteractionActive, shouldShowParagraphSettingMenu, shouldUseInsertBelowRange } from '..';
import { HorizontalLineCommand } from '../../../commands/commands/doc-horizontal-line.command';
import { SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand } from '../../../commands/commands/inline-format.command';
import { BulletListCommand, InsertBulletListBellowCommand, OrderListCommand } from '../../../commands/commands/list.command';
@@ -283,6 +283,16 @@ describe('ParagraphMenu', () => {
expect(openMenu).toHaveBeenCalledTimes(1);
});
+ it('marks the paragraph menu interaction as active while hovering trigger, bridge, or popup', () => {
+ const setParagraphMenuActive = vi.fn();
+
+ setParagraphMenuInteractionActive({ setParagraphMenuActive } as never, true);
+ setParagraphMenuInteractionActive({ setParagraphMenuActive } as never, false);
+
+ expect(setParagraphMenuActive).toHaveBeenNthCalledWith(1, true);
+ expect(setParagraphMenuActive).toHaveBeenNthCalledWith(2, false);
+ });
+
it('maps paragraph named styles to the active heading menu item', () => {
expect(getParagraphMenuActiveHeadingCommandId(NamedStyleType.HEADING_1)).toBe(H1HeadingCommand.id);
expect(getParagraphMenuActiveHeadingCommandId(NamedStyleType.HEADING_3)).toBe(H3HeadingCommand.id);
diff --git a/packages/docs-ui/src/components/paragraph-menu/index.tsx b/packages/docs-ui/src/components/paragraph-menu/index.tsx
index 59bd486ec6..8e56edf86a 100644
--- a/packages/docs-ui/src/components/paragraph-menu/index.tsx
+++ b/packages/docs-ui/src/components/paragraph-menu/index.tsx
@@ -102,6 +102,13 @@ export function createParagraphMenuHoverOpenScheduler(openMenu: () => void, dela
};
}
+export function setParagraphMenuInteractionActive(
+ docParagraphMenuService: Pick<DocParagraphMenuService, 'setParagraphMenuActive'> | null | undefined,
+ active: boolean
+): void {
+ docParagraphMenuService?.setParagraphMenuActive(active);
+}
+
export function isEmptyParagraphMenuTarget(dataStream: string, paragraph?: IMutiPageParagraphBound | null | void): boolean {
if (!paragraph) {
return false;
@@ -645,6 +652,7 @@ export const ParagraphMenu = ({ popup }: { popup: IPopup }) => {
const handleHideMenu = () => {
setVisible(false);
targetRangeRef.current = null;
+ setParagraphMenuInteractionActive(docParagraphMenuService, false);
};
const clearHideTimer = () => {
@@ -666,6 +674,7 @@ export const ParagraphMenu = ({ popup }: { popup: IPopup }) => {
const handleOpenMenu = () => {
clearHideTimer();
const latestTarget = docParagraphMenuService?.activeTarget ?? activeTarget;
+ setParagraphMenuInteractionActive(docParagraphMenuService, true);
const targetRange = latestTarget
? {
...latestTarget.menuRange,
@@ -892,6 +901,7 @@ export const ParagraphMenu = ({ popup }: { popup: IPopup }) => {
hideTimerRef.current = null;
}
hoverOpenSchedulerRef.current.cancel();
+ setParagraphMenuInteractionActive(docParagraphMenuService, false);
}, []);
return (
@@ -911,6 +921,7 @@ export const ParagraphMenu = ({ popup }: { popup: IPopup }) => {
})}
onMouseEnter={(e) => {
popup.onPointerEnter?.(e);
+ setParagraphMenuInteractionActive(docParagraphMenuService, true);
isMouseOver.current = true;
scheduleOpenMenu();
}}
@@ -1037,6 +1048,7 @@ export const ParagraphMenu = ({ popup }: { popup: IPopup }) => {
// Keep hover continuity when the pointer crosses the tiny dead zone between trigger and popup.
onMouseEnter={(e) => {
popup.onPointerEnter?.(e);
+ setParagraphMenuInteractionActive(docParagraphMenuService, true);
isMouseOver.current = true;
clearHideTimer();
}}
@@ -1055,6 +1067,7 @@ export const ParagraphMenu = ({ popup }: { popup: IPopup }) => {
<section
onMouseEnter={(e) => {
popup.onPointerEnter?.(e);
+ setParagraphMenuInteractionActive(docParagraphMenuService, true);
isMouseOver.current = true;
clearHideTimer();
}}
diff --git a/packages/docs-ui/src/controllers/render-controllers/doc-contextmenu.render-controller.ts b/packages/docs-ui/src/controllers/render-controllers/doc-contextmenu.render-controller.ts
index 9f77fb3e7e..1f21785ece 100644
--- a/packages/docs-ui/src/controllers/render-controllers/doc-contextmenu.render-controller.ts
+++ b/packages/docs-ui/src/controllers/render-controllers/doc-contextmenu.render-controller.ts
@@ -63,7 +63,7 @@ export class DocContextMenuRenderController extends Disposable implements IRende
// Content range context menu
const documentsSubscription = documentsPointerDownObserver.subscribeEvent((event) => {
if (event.button === 2) {
- if (this._docEventManagerService.isPointerOnBullet(event.offsetX, event.offsetY)) {
+ if (this._docEventManagerService.isPointerOnNonChecklistBullet(event.offsetX, event.offsetY)) {
return;
}
if (this._isSelectionInCodeBlock()) {
diff --git a/packages/docs-ui/src/index.ts b/packages/docs-ui/src/index.ts
index e6e27328f7..46bf2e1f05 100644
--- a/packages/docs-ui/src/index.ts
+++ b/packages/docs-ui/src/index.ts
@@ -38,6 +38,7 @@ export { type IIMEInputCommandParams, IMEInputCommand } from './commands/command
export {
getStyleInTextRange,
ResetInlineFormatTextBackgroundColorCommand,
+ ResetInlineFormatTextColorCommand,
SetInlineFormatBoldCommand,
SetInlineFormatCommand,
SetInlineFormatFontFamilyCommand,
@@ -110,7 +111,22 @@ export type { IUniverDocsUIConfig } from './config/config';
export { DocUIController } from './controllers/doc-ui.controller';
export { DocBackScrollRenderController } from './controllers/render-controllers/back-scroll.render-controller';
export { DocRenderController } from './controllers/render-controllers/doc.render-controller';
-export { FLOAT_TEXT_STYLE_MENU_ID, FLOAT_TOOLBAR_MENU_POSITION, hideMenuWhenSelectionInBlockRange, isTextRangeInAnyBlockRange } from './menu/menu';
+export {
+ AlignMenuItemFactory,
+ BackgroundColorSelectorMenuItemFactory,
+ BoldMenuItemFactory,
+ FLOAT_TEXT_STYLE_MENU_ID,
+ FLOAT_TOOLBAR_MENU_POSITION,
+ FloatTextStyleMenuItemFactory,
+ FontFamilySelectorMenuItemFactory,
+ FontSizeSelectorMenuItemFactory,
+ hideMenuWhenSelectionInBlockRange,
+ isTextRangeInAnyBlockRange,
+ ItalicMenuItemFactory,
+ StrikeThroughMenuItemFactory,
+ TextColorSelectorMenuItemFactory,
+ UnderlineMenuItemFactory,
+} from './menu/menu';
export {
DOC_CONTENT_INSERT_MENU_ID,
DOC_PARAGRAPH_T_ALIGN_MENU_ID,
@@ -132,7 +148,7 @@ export * from './services';
export { IDocClipboardService } from './services/clipboard/clipboard.service';
export { convertBodyToHtml } from './services/clipboard/udm-to-html/convertor';
export { DocAutoFormatService } from './services/doc-auto-format.service';
-export { DocEventManagerService, type IBulletBound } from './services/doc-event-manager.service';
+export { DocEventManagerService, getListMarkerFallbackBound, getListParagraphContextMenuHit, type IBulletBound, type IMutiPageParagraphBound } from './services/doc-event-manager.service';
export { DocIMEInputManagerService } from './services/doc-ime-input-manager.service';
export { DocParagraphMenuService } from './services/doc-paragraph-menu.service';
export { calcDocRangePositions, DocCanvasPopManagerService } from './services/doc-popup-manager.service';
diff --git a/packages/docs-ui/src/menu/menu.ts b/packages/docs-ui/src/menu/menu.ts
index 4fa9abb845..541a769966 100644
--- a/packages/docs-ui/src/menu/menu.ts
+++ b/packages/docs-ui/src/menu/menu.ts
@@ -59,7 +59,7 @@ import {
import { combineLatest, map, Observable } from 'rxjs';
import { OpenHeaderFooterPanelCommand } from '../commands/commands/doc-header-footer.command';
import { HorizontalLineCommand } from '../commands/commands/doc-horizontal-line.command';
-import { getStyleInTextRange, ResetInlineFormatTextBackgroundColorCommand, SetInlineFormatBoldCommand, SetInlineFormatCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand, SetInlineFormatUnderlineCommand } from '../commands/commands/inline-format.command';
+import { getStyleInTextRange, ResetInlineFormatTextBackgroundColorCommand, ResetInlineFormatTextColorCommand, SetInlineFormatBoldCommand, SetInlineFormatCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand, SetInlineFormatUnderlineCommand } from '../commands/commands/inline-format.command';
import { BulletListCommand, CheckListCommand, OrderListCommand } from '../commands/commands/list.command';
import { AlignCenterCommand, AlignJustifyCommand, AlignLeftCommand, AlignOperationCommand, AlignRightCommand } from '../commands/commands/paragraph-align.command';
import { SetParagraphNamedStyleCommand } from '../commands/commands/set-heading.command';
@@ -1244,6 +1244,15 @@ export function DocSwitchModeMenuItemFactory(accessor: IAccessor): IMenuButtonIt
};
}
+export function ResetTextColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ return {
+ id: ResetInlineFormatTextColorCommand.id,
+ type: MenuItemType.BUTTON,
+ title: 'docs-ui.toolbar.resetColor',
+ icon: 'NoColorDoubleIcon',
+ };
+}
+
export function ResetBackgroundColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: ResetInlineFormatTextBackgroundColorCommand.id,
diff --git a/packages/docs-ui/src/menu/paragraph-menu.ts b/packages/docs-ui/src/menu/paragraph-menu.ts
index d754c13e52..b11a8c74e2 100644
--- a/packages/docs-ui/src/menu/paragraph-menu.ts
+++ b/packages/docs-ui/src/menu/paragraph-menu.ts
@@ -39,7 +39,7 @@ import { Observable } from 'rxjs';
import { DocCopyCommand, DocCopyCurrentParagraphCommand, DocCutCurrentParagraphCommand, DocPasteCommand } from '../commands/commands/clipboard.command';
import { DeleteCurrentParagraphCommand } from '../commands/commands/doc-delete.command';
import { HorizontalLineCommand, InsertHorizontalLineBellowCommand } from '../commands/commands/doc-horizontal-line.command';
-import { ResetInlineFormatTextBackgroundColorCommand, SetInlineFormatFontSizeCommand, SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand } from '../commands/commands/inline-format.command';
+import { ResetInlineFormatTextBackgroundColorCommand, ResetInlineFormatTextColorCommand, SetInlineFormatFontSizeCommand, SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand } from '../commands/commands/inline-format.command';
import { BulletListCommand, CheckListCommand, InsertBulletListBellowCommand, InsertCheckListBellowCommand, InsertOrderListBellowCommand, OrderListCommand } from '../commands/commands/list.command';
import { H1HeadingCommand, H2HeadingCommand, H3HeadingCommand, H4HeadingCommand, H5HeadingCommand, NormalTextHeadingCommand, SubtitleHeadingCommand, TitleHeadingCommand } from '../commands/commands/set-heading.command';
import { DocTableDeleteTableCommand } from '../commands/commands/table/doc-table-delete.command';
@@ -776,6 +776,13 @@ export const ParagraphMenuNoBackgroundMenuItemFactory = createStaticButtonMenuIt
title: 'docs-ui.paragraphMenu.noBackground',
});
+export const ParagraphMenuResetTextColorMenuItemFactory = createStaticButtonMenuItemFactory({
+ id: ResetInlineFormatTextColorCommand.id,
+ icon: 'NoColorDoubleIcon',
+ title: 'docs-ui.toolbar.resetColor',
+ tooltip: 'docs-ui.toolbar.resetColor',
+});
+
export const ParagraphMenuResetColorsMenuItemFactory = createStaticButtonMenuItemFactory({
id: DOC_PARAGRAPH_T_RESET_COLORS_ID,
icon: 'PaintBucketDoubleIcon',
diff --git a/packages/docs-ui/src/menu/schema.ts b/packages/docs-ui/src/menu/schema.ts
index d114a25e17..2a2004db15 100644
--- a/packages/docs-ui/src/menu/schema.ts
+++ b/packages/docs-ui/src/menu/schema.ts
@@ -21,7 +21,7 @@ import { DeleteCurrentParagraphCommand, DeleteLeftCommand } from '../commands/co
import { OpenHeaderFooterPanelCommand } from '../commands/commands/doc-header-footer.command';
import { HorizontalLineCommand, InsertHorizontalLineBellowCommand } from '../commands/commands/doc-horizontal-line.command';
-import { ResetInlineFormatTextBackgroundColorCommand, SetInlineFormatBoldCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand, SetInlineFormatUnderlineCommand } from '../commands/commands/inline-format.command';
+import { ResetInlineFormatTextBackgroundColorCommand, ResetInlineFormatTextColorCommand, SetInlineFormatBoldCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand, SetInlineFormatUnderlineCommand } from '../commands/commands/inline-format.command';
import { BulletListCommand, CheckListCommand, InsertBulletListBellowCommand, InsertCheckListBellowCommand, InsertOrderListBellowCommand, OrderListCommand } from '../commands/commands/list.command';
import { AlignOperationCommand } from '../commands/commands/paragraph-align.command';
import { H1HeadingCommand, H2HeadingCommand, H3HeadingCommand, H4HeadingCommand, H5HeadingCommand, NormalTextHeadingCommand, SetParagraphNamedStyleCommand, SubtitleHeadingCommand, TitleHeadingCommand } from '../commands/commands/set-heading.command';
@@ -74,6 +74,7 @@ import {
OrderListMenuItemFactory,
PageSettingMenuItemFactory,
ResetBackgroundColorMenuItemFactory,
+ ResetTextColorMenuItemFactory,
StrikeThroughMenuItemFactory,
SubscriptMenuItemFactory,
SuperscriptMenuItemFactory,
@@ -153,6 +154,7 @@ import {
ParagraphMenuInsertQuoteMenuItemFactory,
ParagraphMenuInsertShapeMenuItemFactory,
ParagraphMenuNoBackgroundMenuItemFactory,
+ ParagraphMenuResetTextColorMenuItemFactory,
ParagraphMenuTextColorHeaderActionMenuItemFactory,
ParagraphMenuTextColorSwatchMenuItemFactories,
SubtitleHeadingMenuItemFactory,
@@ -213,6 +215,10 @@ export const menuSchema: MenuSchemaType = {
[SetInlineFormatTextColorCommand.id]: {
order: 8,
menuItemFactory: TextColorSelectorMenuItemFactory,
+ [ResetInlineFormatTextColorCommand.id]: {
+ order: 0,
+ menuItemFactory: ResetTextColorMenuItemFactory,
+ },
},
[SetInlineFormatTextBackgroundColorCommand.id]: {
order: 9,
@@ -886,6 +892,10 @@ export const menuSchema: MenuSchemaType = {
order: 0,
menuItemFactory: ParagraphMenuDefaultTextColorMenuItemFactory,
},
+ [ResetInlineFormatTextColorCommand.id]: {
+ order: 8,
+ menuItemFactory: ParagraphMenuResetTextColorMenuItemFactory,
+ },
...ParagraphMenuTextColorSwatchMenuItemFactories,
},
backgroundTop: {
diff --git a/packages/docs-ui/src/plugin.ts b/packages/docs-ui/src/plugin.ts
index 9350ed7588..b34b6d4349 100644
--- a/packages/docs-ui/src/plugin.ts
+++ b/packages/docs-ui/src/plugin.ts
@@ -48,6 +48,7 @@ import { DocSelectAllCommand } from './commands/commands/doc-select-all.command'
import { IMEInputCommand } from './commands/commands/ime-input.command';
import {
ResetInlineFormatTextBackgroundColorCommand,
+ ResetInlineFormatTextColorCommand,
SetInlineFormatBoldCommand,
SetInlineFormatCommand,
SetInlineFormatFontFamilyCommand,
@@ -212,6 +213,7 @@ export class UniverDocsUIPlugin extends Plugin {
SetInlineFormatFontSizeCommand,
SetInlineFormatFontFamilyCommand,
SetInlineFormatTextColorCommand,
+ ResetInlineFormatTextColorCommand,
SetInlineFormatTextFillCommand,
ResetInlineFormatTextBackgroundColorCommand,
SetInlineFormatTextBackgroundColorCommand,
diff --git a/packages/docs-ui/src/services/__tests__/doc-paragraph-menu.service.spec.ts b/packages/docs-ui/src/services/__tests__/doc-paragraph-menu.service.spec.ts
index e13b4845e5..1a153ee8ec 100644
--- a/packages/docs-ui/src/services/__tests__/doc-paragraph-menu.service.spec.ts
+++ b/packages/docs-ui/src/services/__tests__/doc-paragraph-menu.service.spec.ts
@@ -186,6 +186,130 @@ describe('DocParagraphMenuService', () => {
expect(service.activeTarget?.cellRange).toEqual({ startOffset: 2, endOffset: 8 });
});
+ it('does not let the same table hover target steal back a cell paragraph menu', () => {
+ const disposeTableMenu = vi.fn();
+ const disposeCellMenu = vi.fn();
+ const attachPopupToRect = vi.fn()
+ .mockReturnValueOnce({ canDispose: () => true, dispose: disposeTableMenu })
+ .mockReturnValueOnce({ canDispose: () => true, dispose: disposeCellMenu });
+ const service = createService({
+ attachPopupToRect,
+ dataStream: `${DataStreamTreeTokenType.TABLE_START}${DataStreamTreeTokenType.TABLE_ROW_START}${DataStreamTreeTokenType.TABLE_CELL_START}Cell\r${DataStreamTreeTokenType.TABLE_CELL_END}${DataStreamTreeTokenType.TABLE_ROW_END}${DataStreamTreeTokenType.TABLE_END}`,
+ tables: [{ tableId: 'table-1', startIndex: 0, endIndex: 9 }],
+ });
+ const tableBound = {
+ pageIndex: 0,
+ rect: {
+ bottom: 170,
+ left: 100,
+ right: 400,
+ top: 80,
+ },
+ tableId: 'table-1',
+ };
+
+ service.showTableMenu(tableBound);
+ service.showParagraphMenu(createParagraphBound({
+ paragraphStart: 3,
+ paragraphEnd: 7,
+ startIndex: 7,
+ }));
+ service.showTableMenu(tableBound);
+
+ expect(service.activeTarget?.kind).toBe('paragraph');
+ expect(service.activeTarget?.key).toBe('paragraph:7');
+ expect(disposeCellMenu).not.toHaveBeenCalled();
+ expect(attachPopupToRect).toHaveBeenCalledTimes(2);
+ });
+
+ it('anchors first-column table-cell paragraph menus to the left of the row header lane', () => {
+ const attachPopupToRect = vi.fn(() => ({ canDispose: () => true, dispose: vi.fn() }));
+ const paragraph = {
+ ...createParagraphBound({
+ paragraphStart: 3,
+ paragraphEnd: 7,
+ startIndex: 7,
+ }),
+ firstLine: { bottom: 140, left: 140, right: 240, top: 120 },
+ rowIndex: 0,
+ colIndex: 0,
+ tableId: 'table-1',
+ };
+ const service = createService({
+ attachPopupToRect,
+ dataStream: `${DataStreamTreeTokenType.TABLE_START}${DataStreamTreeTokenType.TABLE_ROW_START}${DataStreamTreeTokenType.TABLE_CELL_START}Cell\r${DataStreamTreeTokenType.TABLE_CELL_END}${DataStreamTreeTokenType.TABLE_ROW_END}${DataStreamTreeTokenType.TABLE_END}`,
+ findParagraphBoundByIndex: vi.fn(() => paragraph),
+ tableCellBounds: new Map([[
+ 'table-1',
+ [{
+ rect: { bottom: 180, left: 100, right: 260, top: 100 },
+ pageIndex: 0,
+ rowIndex: 0,
+ colIndex: 0,
+ tableId: 'table-1',
+ }],
+ ]]),
+ tables: [{ tableId: 'table-1', startIndex: 0, endIndex: 9 }],
+ });
+
+ service.showParagraphMenu(paragraph as IMutiPageParagraphBound);
+
+ const [anchor] = attachPopupToRect.mock.calls[0] as unknown as [() => { bottom: number; left: number; right: number; top: number }];
+ expect(anchor()).toEqual({
+ bottom: 140,
+ left: 80,
+ right: 80,
+ top: 120,
+ });
+ });
+
+ it('keeps non-first-column table-cell paragraph menus clear of the column resize edge', () => {
+ const attachPopupToRect = vi.fn(() => ({ canDispose: () => true, dispose: vi.fn() }));
+ const paragraph = {
+ ...createParagraphBound({
+ paragraphStart: 3,
+ paragraphEnd: 7,
+ startIndex: 7,
+ }),
+ firstLine: { bottom: 140, left: 300, right: 400, top: 120 },
+ rowIndex: 0,
+ colIndex: 1,
+ tableId: 'table-1',
+ };
+ const service = createService({
+ attachPopupToRect,
+ dataStream: `${DataStreamTreeTokenType.TABLE_START}${DataStreamTreeTokenType.TABLE_ROW_START}${DataStreamTreeTokenType.TABLE_CELL_START}A${DataStreamTreeTokenType.TABLE_CELL_END}${DataStreamTreeTokenType.TABLE_CELL_START}Cell\r${DataStreamTreeTokenType.TABLE_CELL_END}${DataStreamTreeTokenType.TABLE_ROW_END}${DataStreamTreeTokenType.TABLE_END}`,
+ findParagraphBoundByIndex: vi.fn(() => paragraph),
+ tableCellBounds: new Map([[
+ 'table-1',
+ [{
+ rect: { bottom: 180, left: 100, right: 260, top: 100 },
+ pageIndex: 0,
+ rowIndex: 0,
+ colIndex: 0,
+ tableId: 'table-1',
+ }, {
+ rect: { bottom: 180, left: 280, right: 440, top: 100 },
+ pageIndex: 0,
+ rowIndex: 0,
+ colIndex: 1,
+ tableId: 'table-1',
+ }],
+ ]]),
+ tables: [{ tableId: 'table-1', startIndex: 0, endIndex: 12 }],
+ });
+
+ service.showParagraphMenu(paragraph as IMutiPageParagraphBound);
+
+ const [anchor] = attachPopupToRect.mock.calls[0] as unknown as [() => { bottom: number; left: number; right: number; top: number }];
+ expect(anchor()).toEqual({
+ bottom: 140,
+ left: 270,
+ right: 270,
+ top: 120,
+ });
+ });
+
it('uses list icons for list paragraph menus', () => {
const attachPopupToRect = vi.fn(() => ({ canDispose: () => true, dispose: vi.fn() }));
const service = createService({
@@ -312,6 +436,7 @@ function createService(options: {
findParagraphBoundByIndex?: (index: number) => unknown;
paragraphs?: Array<{ bullet?: { listType?: PresetListType }; startIndex: number }>;
paragraphBounds?: Map<number, IMutiPageParagraphBound>;
+ tableCellBounds?: Map<string, Array<{ colIndex: number; pageIndex: number; rect: { bottom: number; left: number; right: number; top: number }; rowIndex: number; tableId: string }>>;
tables?: Array<{ endIndex: number; startIndex: number; tableId: string }>;
viewportScrollY?: number;
}) {
@@ -354,6 +479,11 @@ function createService(options: {
findParagraphBoundByIndex: options.findParagraphBoundByIndex ?? vi.fn(() => null),
findParagraphBoundsInRange: vi.fn((startIndex: number, endIndex: number) => [...(options.paragraphBounds ?? new Map()).values()]
.filter((bound) => Math.max(bound.paragraphStart, startIndex) <= Math.min(bound.paragraphEnd, endIndex))),
+ findTableCellBound: vi.fn((tableId: string, rowIndex: number, colIndex: number, pageIndex?: number) => options.tableCellBounds?.get(tableId)?.find((bound) =>
+ bound.rowIndex === rowIndex &&
+ bound.colIndex === colIndex &&
+ (pageIndex == null || bound.pageIndex === pageIndex)
+ )),
paragraphBounds: options.paragraphBounds ?? new Map(),
tableBounds: new Map(),
} as never,
diff --git a/packages/docs-ui/src/services/__tests__/doc-services.spec.ts b/packages/docs-ui/src/services/__tests__/doc-services.spec.ts
index 1e25f8aabe..3c03c5b34b 100644
--- a/packages/docs-ui/src/services/__tests__/doc-services.spec.ts
+++ b/packages/docs-ui/src/services/__tests__/doc-services.spec.ts
@@ -15,13 +15,14 @@
*/
import type { IDocumentData, Injector, ITextStyle, Univer } from '@univerjs/core';
-import { CustomRangeType, DocumentFlavor, IUniverInstanceService } from '@univerjs/core';
+import { CustomRangeType, DocumentFlavor, IUniverInstanceService, PresetListType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
import { DocumentEditArea } from '@univerjs/engine-render';
import { Subject } from 'rxjs';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { createCommandTestBed } from '../../commands/commands/__tests__/create-command-test-bed';
import { DocAutoFormatService } from '../doc-auto-format.service';
+import { getListMarkerFallbackBound, getListMarkerFallbackHit, getListParagraphContextMenuHit, isChecklistListType } from '../doc-event-manager.service';
import { DocMenuStyleService } from '../doc-menu-style.service';
import { DocPrintInterceptorService } from '../doc-print-interceptor.service';
import { DocsRenderService } from '../docs-render.service';
@@ -74,6 +75,67 @@ describe('docs ui services', () => {
univer?.dispose();
});
+ it('detects a list marker fallback hit from paragraph bounds without treating body text as marker', () => {
+ const paragraph = {
+ startIndex: 12,
+ bullet: {
+ listId: 'list-1',
+ listType: 'bulletList',
+ nestingLevel: 0,
+ },
+ };
+ const paragraphBound = {
+ firstLine: { bottom: 124, left: 160, right: 460, top: 104 },
+ pageIndex: 0,
+ rect: { bottom: 128, left: 160, right: 460, top: 100 },
+ segmentId: undefined,
+ };
+
+ expect(getListMarkerFallbackBound(paragraphBound, paragraph)).toEqual({
+ paragraph,
+ rect: { bottom: 124, left: 160, right: 196, top: 104 },
+ segmentId: undefined,
+ segmentPageIndex: 0,
+ });
+ expect(getListMarkerFallbackHit(paragraphBound, paragraph, { x: 168, y: 112 })).toEqual({
+ paragraph,
+ rect: { bottom: 124, left: 160, right: 196, top: 104 },
+ segmentId: undefined,
+ segmentPageIndex: 0,
+ });
+ expect(getListMarkerFallbackHit(paragraphBound, paragraph, { x: 240, y: 112 })).toBeNull();
+ expect(getListMarkerFallbackHit(paragraphBound, { startIndex: 12 }, { x: 168, y: 112 })).toBeNull();
+ });
+
+ it('does not treat list paragraph body hits as list marker context menu hits', () => {
+ const paragraph = {
+ startIndex: 12,
+ bullet: {
+ listId: 'list-1',
+ listType: 'bulletList',
+ nestingLevel: 0,
+ },
+ };
+ const paragraphBound = {
+ firstLine: { bottom: 124, left: 160, right: 460, top: 104 },
+ pageIndex: 0,
+ rect: { bottom: 128, left: 160, right: 460, top: 100 },
+ segmentId: undefined,
+ };
+
+ expect(getListMarkerFallbackHit(paragraphBound, paragraph, { x: 260, y: 112 })).toBeNull();
+ expect(getListParagraphContextMenuHit(paragraphBound, paragraph, { x: 260, y: 112 })).toBeNull();
+ expect(getListParagraphContextMenuHit(paragraphBound, paragraph, { x: 260, y: 180 })).toBeNull();
+ expect(getListParagraphContextMenuHit(paragraphBound, { startIndex: 12 }, { x: 260, y: 112 })).toBeNull();
+ });
+
+ it('identifies checklist list types separately from interactive list markers', () => {
+ expect(isChecklistListType(PresetListType.CHECK_LIST)).toBe(true);
+ expect(isChecklistListType(PresetListType.CHECK_LIST_CHECKED)).toBe(true);
+ expect(isChecklistListType(PresetListType.BULLET_LIST)).toBe(false);
+ expect(isChecklistListType(PresetListType.ORDER_LIST)).toBe(false);
+ });
+
it('matches auto-format handlers by priority and builds context from the current selection', () => {
({ univer, get } = createCommandTestBed(createDocData()));
const selectionManager = get(DocSelectionManagerService);
diff --git a/packages/docs-ui/src/services/doc-event-manager.service.ts b/packages/docs-ui/src/services/doc-event-manager.service.ts
index 24abd20ad7..d79a4446fa 100644
--- a/packages/docs-ui/src/services/doc-event-manager.service.ts
+++ b/packages/docs-ui/src/services/doc-event-manager.service.ts
@@ -26,7 +26,7 @@ import type {
IRenderContext,
IRenderModule,
} from '@univerjs/engine-render';
-import { Disposable, fromEventSubject, Inject } from '@univerjs/core';
+import { Disposable, fromEventSubject, Inject, PresetListType } from '@univerjs/core';
import { DocSkeletonManagerService } from '@univerjs/docs';
import { CURSOR_TYPE, getDocsTableRenderViewport, getTableIdAndSliceIndex, TRANSFORM_CHANGE_OBSERVABLE_TYPE } from '@univerjs/engine-render';
import { BehaviorSubject, distinctUntilChanged, filter, map, Subject, switchMap, take, throttleTime } from 'rxjs';
@@ -158,6 +158,55 @@ export const calcDocGlyphPosition = (glyph: IDocumentSkeletonGlyph, documents: D
};
};
+const LIST_MARKER_FALLBACK_HIT_WIDTH = 36;
+
+export function getListMarkerFallbackHit(
+ paragraphBound: Pick<IMutiPageParagraphBound, 'firstLine' | 'pageIndex' | 'rect' | 'segmentId'>,
+ paragraph: Pick<IParagraph, 'bullet' | 'startIndex'> | undefined,
+ point: { x: number; y: number }
+): IBulletBound | null {
+ const markerBound = getListMarkerFallbackBound(paragraphBound, paragraph);
+
+ if (!markerBound || !isPointInRect(point.x, point.y, markerBound.rect)) {
+ return null;
+ }
+
+ return markerBound;
+}
+
+export function getListParagraphContextMenuHit(
+ paragraphBound: Pick<IMutiPageParagraphBound, 'firstLine' | 'pageIndex' | 'rect' | 'segmentId'>,
+ paragraph: Pick<IParagraph, 'bullet' | 'startIndex'> | undefined,
+ point: { x: number; y: number }
+): IBulletBound | null {
+ return getListMarkerFallbackHit(paragraphBound, paragraph, point);
+}
+
+export function isChecklistListType(listType?: string): boolean {
+ return listType === PresetListType.CHECK_LIST || listType === PresetListType.CHECK_LIST_CHECKED;
+}
+
+export function getListMarkerFallbackBound(
+ paragraphBound: Pick<IMutiPageParagraphBound, 'firstLine' | 'pageIndex' | 'rect' | 'segmentId'>,
+ paragraph: Pick<IParagraph, 'bullet' | 'startIndex'> | undefined
+): IBulletBound | null {
+ if (!paragraph?.bullet) {
+ return null;
+ }
+
+ return {
+ paragraph: paragraph as IParagraph,
+ rect: {
+ bottom: paragraphBound.firstLine.bottom,
+ left: paragraphBound.rect.left,
+ right: Math.min(paragraphBound.rect.right, paragraphBound.rect.left + LIST_MARKER_FALLBACK_HIT_WIDTH),
+ top: paragraphBound.firstLine.top,
+ },
+ segmentId: paragraphBound.segmentId,
+ segmentPageIndex: paragraphBound.pageIndex,
+ };
+}
+
interface ICustomRangeActive {
range: ICustomRange;
segmentId?: string;
@@ -416,12 +465,12 @@ export class DocEventManagerService extends Disposable implements IRenderModule
const onPointerUp$ = fromEventSubject(this._context.scene!.onPointerUp$);
this.disposeWithMe(onPointerDown$.pipe(
switchMap((down) => onPointerUp$.pipe(take(1), map((up) => ({ down, up })))),
- filter(({ down, up }) => down.target === up.target && up.timeStamp - down.timeStamp < 300)
+ filter(({ down, up }) => down.target === up.target && (down.button === 2 || up.timeStamp - down.timeStamp < 300))
).subscribe(({ down }) => {
const point = transformOffset2Bound(down.offsetX, down.offsetY, this._context.scene);
if (down.button === 2) {
- const bullet = this._calcActiveBullet(point);
+ const bullet = this._calcActiveBullet(point) ?? this._calcActiveListParagraph(point);
if (bullet) {
this._contextMenuBullet$.next({
...bullet,
@@ -449,12 +498,24 @@ export class DocEventManagerService extends Disposable implements IRenderModule
return Boolean(this._calcActiveBullet(transformOffset2Bound(offsetX, offsetY, this._context.scene)));
}
+ isPointerOnNonChecklistBullet(offsetX: number, offsetY: number): boolean {
+ const bullet = this._calcActiveBullet(transformOffset2Bound(offsetX, offsetY, this._context.scene));
+
+ return Boolean(bullet && !isChecklistListType(bullet.paragraph.bullet?.listType));
+ }
+
getBulletBounds(): IBulletBound[] {
this._buildBulletBounds();
return [...this._bulletBounds];
}
+ getListContextMenuBulletByOffset(offsetX: number, offsetY: number): Nullable<IBulletBound> {
+ const point = transformOffset2Bound(offsetX, offsetY, this._context.scene);
+
+ return this._calcActiveBullet(point) ?? this._calcActiveListParagraph(point);
+ }
+
private _buildCustomRangeBoundsBySegment(segmentId?: string, segmentPage = -1) {
const customRanges = this._context.unit.getSelfOrHeaderFooterModel(segmentId)?.getBody()?.customRanges ?? [];
const layouts: ICustomRangeBound[] = [];
@@ -607,7 +668,37 @@ export class DocEventManagerService extends Disposable implements IRenderModule
const { x, y } = evt;
const bullet = this._bulletBounds.find((layout) => isPointInRect(x, y, layout.rect));
- return bullet;
+ if (bullet) {
+ return bullet;
+ }
+
+ const paragraphBound = this._calcActiveParagraph(evt);
+ if (!paragraphBound) {
+ return null;
+ }
+
+ return getListMarkerFallbackHit(
+ paragraphBound,
+ this._getParagraphByStartIndex(paragraphBound.startIndex, paragraphBound.segmentId),
+ evt
+ );
+ }
+
+ private _calcActiveListParagraph(evt: { x: number; y: number }) {
+ const paragraphBound = this._calcActiveParagraph(evt);
+ if (!paragraphBound) {
+ return null;
+ }
+
+ return getListParagraphContextMenuHit(
+ paragraphBound,
+ this._getParagraphByStartIndex(paragraphBound.startIndex, paragraphBound.segmentId),
+ evt
+ );
+ }
+
+ private _getParagraphByStartIndex(startIndex: number, segmentId?: string): IParagraph | undefined {
+ return this._context.unit.getSelfOrHeaderFooterModel(segmentId)?.getBody()?.paragraphs?.find((paragraph) => paragraph.startIndex === startIndex);
}
// eslint-disable-next-line max-lines-per-function
@@ -839,6 +930,15 @@ export class DocEventManagerService extends Disposable implements IRenderModule
return this._tableBounds;
}
+ findTableCellBound(tableId: string, rowIndex: number, colIndex: number, pageIndex?: number) {
+ this._buildParagraphBounds();
+ return this._tableCellBounds.get(tableId)?.find((bound) => (
+ bound.rowIndex === rowIndex &&
+ bound.colIndex === colIndex &&
+ (pageIndex == null || bound.pageIndex === pageIndex)
+ ));
+ }
+
findParagraphBoundByIndex(index: number) {
this._buildParagraphBounds();
const tableParagraph = Array.from(this._tableParagraphBounds.values()).flat().find((bound) => bound.startIndex === index);
diff --git a/packages/docs-ui/src/services/doc-paragraph-menu.service.ts b/packages/docs-ui/src/services/doc-paragraph-menu.service.ts
index e46fb8408c..16b6078bc4 100644
--- a/packages/docs-ui/src/services/doc-paragraph-menu.service.ts
+++ b/packages/docs-ui/src/services/doc-paragraph-menu.service.ts
@@ -16,7 +16,7 @@
import type { DocumentDataModel, ICustomBlock, ICustomTable, IDocumentBlockRange, INeedCheckDisposable, Nullable } from '@univerjs/core';
import type { IBoundRectNoAngle, IRenderContext, IRenderModule } from '@univerjs/engine-render';
-import type { IMutiPageParagraphBound, ITableBound } from './doc-event-manager.service';
+import type { IMutiPageParagraphBound, ITableBound, ITableParagraphBound } from './doc-event-manager.service';
import { BlockType, DataStreamTreeTokenType, Disposable, Inject, isInternalEditorID, PresetListType } from '@univerjs/core';
import { DocSelectionManagerService, DocSkeletonManagerService } from '@univerjs/docs';
import { DocumentEditArea } from '@univerjs/engine-render';
@@ -252,9 +252,18 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
const targetParagraph = target.paragraph ?? paragraph;
const blockRange = target.blockRange;
- const getFirstLine = () => blockRange
- ? getBlockRangeAnchorRect(this._docEventManagerService, blockRange, paragraph)
- : this._docEventManagerService.findParagraphBoundByIndex(paragraph.startIndex)?.firstLine ?? paragraph.firstLine;
+ const getFirstLine = () => {
+ const latestParagraphBound = this._docEventManagerService.findParagraphBoundByIndex(targetParagraph.startIndex) ?? targetParagraph;
+ const baseAnchor = blockRange
+ ? getBlockRangeAnchorRect(this._docEventManagerService, blockRange, paragraph)
+ : latestParagraphBound.firstLine ?? paragraph.firstLine;
+
+ if (!target.cellRange) {
+ return baseAnchor;
+ }
+
+ return getTableCellParagraphAnchorRect(this._docEventManagerService, latestParagraphBound, baseAnchor);
+ };
const disposable = this._docPopupManagerService.attachPopupToRect(
getFirstLine,
@@ -308,6 +317,10 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
draggable: true,
};
+ if (this._shouldKeepCurrentCellMenuForTable(table)) {
+ return;
+ }
+
if (this._paragrahMenu?.target.key === target.key) {
return;
}
@@ -347,6 +360,16 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
this._activeTarget$.next(target);
}
+ private _shouldKeepCurrentCellMenuForTable(table: ICustomTable): boolean {
+ const target = this._paragrahMenu?.target;
+ if (!target || target.kind === 'table' || !target.cellRange) {
+ return false;
+ }
+
+ return target.cellRange.startOffset >= table.startIndex &&
+ target.cellRange.startOffset <= table.endIndex;
+ }
+
getDropTargetFromClientPoint(clientX: number, clientY: number, sourceRange: { startOffset: number; endOffset: number }): IDocBlockDropTarget | null {
const canvasRect = this._context.engine.getCanvasElement().getBoundingClientRect();
const point = transformOffset2Bound(clientX - canvasRect.left, clientY - canvasRect.top, this._context.scene);
@@ -680,6 +703,42 @@ function getTableAnchorRect(tableBound: ITableBound) {
};
}
+const TABLE_CELL_PARAGRAPH_MENU_GAP = 4;
+const TABLE_CELL_PARAGRAPH_MENU_RESIZE_SAFE_GAP = 10;
+const TABLE_CELL_PARAGRAPH_MENU_FIRST_COLUMN_EXTRA_OFFSET = 16;
+
+function getTableCellParagraphAnchorRect(
+ docEventManagerService: DocEventManagerService,
+ paragraph: IMutiPageParagraphBound | ITableParagraphBound,
+ baseAnchor: IBoundRectNoAngle
+) {
+ const tableParagraph = paragraph as IMutiPageParagraphBound & Partial<ITableParagraphBound>;
+ if (!tableParagraph.tableId || tableParagraph.rowIndex == null || tableParagraph.colIndex == null) {
+ return baseAnchor;
+ }
+
+ const cellBound = docEventManagerService.findTableCellBound(
+ tableParagraph.tableId,
+ tableParagraph.rowIndex,
+ tableParagraph.colIndex,
+ tableParagraph.pageIndex
+ );
+
+ if (!cellBound) {
+ return baseAnchor;
+ }
+
+ const gap = tableParagraph.colIndex === 0
+ ? TABLE_CELL_PARAGRAPH_MENU_GAP + TABLE_CELL_PARAGRAPH_MENU_FIRST_COLUMN_EXTRA_OFFSET
+ : TABLE_CELL_PARAGRAPH_MENU_RESIZE_SAFE_GAP;
+ const left = cellBound.rect.left - gap;
+ return {
+ ...baseAnchor,
+ left,
+ right: left,
+ };
+}
+
function unionRects(rects: IBoundRectNoAngle[]): IBoundRectNoAngle | null {
if (!rects.length) {
return null;
diff --git a/packages/ui/src/components/menu/desktop/DesignTinyMenuGroup.tsx b/packages/ui/src/components/menu/desktop/DesignTinyMenuGroup.tsx
index f7bd97aa3e..c4e13f2284 100644
--- a/packages/ui/src/components/menu/desktop/DesignTinyMenuGroup.tsx
+++ b/packages/ui/src/components/menu/desktop/DesignTinyMenuGroup.tsx
@@ -20,10 +20,12 @@ import { clsx, Tooltip } from '@univerjs/design';
export type TinyMenuSizeVariant = 'default' | 'paragraph-t';
export type TinyMenuLayoutVariant = 'default' | 'compact';
+const ICON_EXTEND = { colorChannel1: 'var(--univer-primary-600)' };
+
export interface ITinyMenuItem {
onClick: () => void;
className: string;
- Icon: ComponentType<{ className?: string }>;
+ Icon: ComponentType<{ className?: string; extend?: { colorChannel1?: string } }>;
iconClassName?: string;
key: string;
active?: boolean;
@@ -97,6 +99,7 @@ export function DesignTinyMenuGroup({ items, columns, sizeVariant = 'default', l
: 'univer-size-4',
item.iconClassName
)}
+ extend={ICON_EXTEND}
/>
</div>
);
diff --git a/packages/ui/src/components/menu/desktop/__tests__/DesignTinyMenuGroup.spec.tsx b/packages/ui/src/components/menu/desktop/__tests__/DesignTinyMenuGroup.spec.tsx
index 4e6b37e1d1..36d98b0317 100644
--- a/packages/ui/src/components/menu/desktop/__tests__/DesignTinyMenuGroup.spec.tsx
+++ b/packages/ui/src/components/menu/desktop/__tests__/DesignTinyMenuGroup.spec.tsx
@@ -46,4 +46,22 @@ describe('DesignTinyMenuGroup', () => {
expect(button?.className ?? '').toContain('univer-rounded-sm');
expect(icon?.className ?? '').toContain('univer-size-5');
});
+
+ it('uses the primary color channel for two-channel icons', () => {
+ const Icon = ({ extend }: { className?: string; extend?: { colorChannel1?: string } }) => (
+ React.createElement('span', { 'data-color-channel': extend?.colorChannel1 })
+ );
+ const { container } = render(
+ <DesignTinyMenuGroup
+ items={[{
+ key: 'reset',
+ onClick: () => {},
+ className: '',
+ Icon,
+ }]}
+ />
+ );
+
+ expect(container.querySelector('[data-color-channel]')?.getAttribute('data-color-channel')).toBe('var(--univer-primary-600)');
+ });
});