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.

feat(base-sheets): add clear all,clear formats (#265)

Dushusirfb0366887d75
diff --git a/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts b/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts
index 929deeb636..27b2f761df 100644
--- a/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts
+++ b/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts
@@ -7,7 +7,9 @@ import {
AddWorksheetMergeHorizontalCommand,
AddWorksheetMergeVerticalCommand,
} from '../commands/commands/add-worksheet-merge.command';
+import { ClearSelectionAllCommand } from '../commands/commands/clear-selection-all.command';
import { ClearSelectionContentCommand } from '../commands/commands/clear-selection-content.command';
+import { ClearSelectionFormatCommand } from '../commands/commands/clear-selection-format.command';
import { CopySheetCommand } from '../commands/commands/copy-worksheet.command';
import { DeleteRangeMoveLeftCommand } from '../commands/commands/delete-range-move-left.command';
import { DeleteRangeMoveUpCommand } from '../commands/commands/delete-range-move-up.command';
@@ -105,6 +107,8 @@ export class BasicWorksheetController extends Disposable implements IDisposable
RemoveWorksheetMergeCommand,
RemoveWorksheetMergeMutation,
ClearSelectionContentCommand,
+ ClearSelectionFormatCommand,
+ ClearSelectionAllCommand,
SetRangeValuesMutation,
SetWorksheetNameCommand,
SetWorksheetNameMutation,
diff --git a/packages/base-sheets/src/Controller/sheet-render.controller.ts b/packages/base-sheets/src/Controller/sheet-render.controller.ts
index 5e0efa5c0f..d30279a107 100644
--- a/packages/base-sheets/src/Controller/sheet-render.controller.ts
+++ b/packages/base-sheets/src/Controller/sheet-render.controller.ts
@@ -22,6 +22,8 @@ import { InsertColMutation, InsertRowMutation } from '../commands/mutations/inse
import { MoveRowsMutation } from '../commands/mutations/move-rows-cols.mutation';
import { RemoveColMutation, RemoveRowMutation } from '../commands/mutations/remove-row-col.mutation';
import { RemoveWorksheetMergeMutation } from '../commands/mutations/remove-worksheet-merge.mutation';
+import { SetBorderStylesMutation } from '../commands/mutations/set-border-styles.mutation';
+import { SetRangeValuesMutation } from '../commands/mutations/set-range-values.mutation';
import { SetWorksheetActivateMutation } from '../commands/mutations/set-worksheet-activate.mutation';
import { SetWorksheetColWidthMutation } from '../commands/mutations/set-worksheet-col-width.mutation';
import { SetWorksheetRowHeightMutation } from '../commands/mutations/set-worksheet-row-height.mutation';
@@ -108,6 +110,8 @@ export class SheetRenderController extends Disposable {
AddWorksheetMergeMutation.id,
RemoveWorksheetMergeMutation.id,
MoveRowsMutation.id,
+ SetRangeValuesMutation.id,
+ SetBorderStylesMutation.id,
];
this.disposeWithMe(
diff --git a/packages/base-sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts
index 48f3152a3d..c456a1611c 100644
--- a/packages/base-sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts
+++ b/packages/base-sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts
@@ -2,6 +2,7 @@ import {
ICellData,
ICommandService,
ICurrentUniverService,
+ IRange,
IStyleData,
Nullable,
RANGE_TYPE,
@@ -13,7 +14,10 @@ import { Injector } from '@wendellhu/redi';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { NORMAL_SELECTION_PLUGIN_NAME, SelectionManagerService } from '../../../services/selection-manager.service';
+import { AddWorksheetMergeMutation } from '../../mutations/add-worksheet-merge.mutation';
+import { RemoveWorksheetMergeMutation } from '../../mutations/remove-worksheet-merge.mutation';
import { SetRangeValuesMutation } from '../../mutations/set-range-values.mutation';
+import { AddWorksheetMergeCommand } from '../add-worksheet-merge.command';
import { ClearSelectionAllCommand } from '../clear-selection-all.command';
import { ClearSelectionContentCommand } from '../clear-selection-content.command';
import { ClearSelectionFormatCommand } from '../clear-selection-format.command';
@@ -33,6 +37,9 @@ describe('Test clear selection content commands', () => {
commandService = get(ICommandService);
commandService.registerCommand(ClearSelectionContentCommand);
commandService.registerCommand(ClearSelectionFormatCommand);
+ commandService.registerCommand(AddWorksheetMergeCommand);
+ commandService.registerCommand(AddWorksheetMergeMutation);
+ commandService.registerCommand(RemoveWorksheetMergeMutation);
commandService.registerCommand(ClearSelectionAllCommand);
commandService.registerCommand(SetRangeValuesCommand);
commandService.registerCommand(SetRangeValuesMutation);
@@ -42,7 +49,7 @@ describe('Test clear selection content commands', () => {
univer.dispose();
});
- describe('clear selection content', () => {
+ describe('clear selection contents', () => {
describe('correct situations', () => {
it('will clear selection content when there is a selected range', async () => {
const selectionManager = get(SelectionManagerService);
@@ -77,6 +84,9 @@ describe('Test clear selection content commands', () => {
// redo
expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();
expect(getValue()).toStrictEqual({});
+
+ // Restore the original data
+ expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();
});
});
@@ -87,7 +97,7 @@ describe('Test clear selection content commands', () => {
});
});
});
- describe('clear selection format', () => {
+ describe('clear selection formats', () => {
describe('correct situations', () => {
it('will clear selection format when there is a selected range', async () => {
const selectionManager = get(SelectionManagerService);
@@ -136,7 +146,9 @@ describe('Test clear selection content commands', () => {
// clear formats
expect(await commandService.executeCommand(ClearSelectionFormatCommand.id)).toBeTruthy();
- expect(getValue()).toStrictEqual({});
+ expect(getValue()).toStrictEqual({
+ v: 'A1',
+ });
// undo
expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();
@@ -145,7 +157,88 @@ describe('Test clear selection content commands', () => {
});
// redo
expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();
- expect(getValue()).toStrictEqual({});
+ expect(getValue()).toStrictEqual({
+ v: 'A1',
+ });
+ });
+ it('clear formats with merged cells', async () => {
+ const selectionManager = get(SelectionManagerService);
+ selectionManager.setCurrentSelection({
+ pluginName: NORMAL_SELECTION_PLUGIN_NAME,
+ unitId: 'test',
+ sheetId: 'sheet1',
+ });
+ selectionManager.add([
+ {
+ range: { startRow: 0, startColumn: 0, endColumn: 1, endRow: 1, rangeType: RANGE_TYPE.NORMAL },
+ primary: null,
+ style: null,
+ },
+ ]);
+
+ function getValue(): Nullable<ICellData> {
+ return get(ICurrentUniverService)
+ .getUniverSheetInstance('test')
+ ?.getSheetBySheetId('sheet1')
+ ?.getRange(0, 0, 0, 0)
+ .getValue();
+ }
+
+ function getStyle(): Nullable<IStyleData> {
+ const value = getValue();
+ const styles = get(ICurrentUniverService).getUniverSheetInstance('test')?.getStyles();
+ if (value && styles) {
+ return styles.getStyleByCell(value);
+ }
+ }
+
+ function getMerge(): IRange[] | undefined {
+ return get(ICurrentUniverService)
+ .getUniverSheetInstance('test')
+ ?.getSheetBySheetId('sheet1')
+ ?.getConfig().mergeData;
+ }
+
+ // set formats
+ const paramsStyle: ISetRangeValuesCommandParams = {
+ value: {
+ s: {
+ ff: 'Arial',
+ },
+ },
+ };
+
+ // set style
+ expect(await commandService.executeCommand(SetRangeValuesCommand.id, paramsStyle)).toBeTruthy();
+ expect(getStyle()).toStrictEqual({
+ ff: 'Arial',
+ });
+
+ // set merge cell
+ expect(await commandService.executeCommand(AddWorksheetMergeCommand.id)).toBeTruthy();
+ expect(getMerge()).toStrictEqual([{ startRow: 0, startColumn: 0, endRow: 1, endColumn: 1 }]);
+
+ // clear formats with merged cells
+ expect(await commandService.executeCommand(ClearSelectionFormatCommand.id)).toBeTruthy();
+ // clear formats
+ expect(getValue()).toStrictEqual({
+ v: 'A1',
+ });
+ // remove merge
+ expect(getMerge()).toStrictEqual([]);
+
+ // undo
+ expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();
+ expect(getStyle()).toStrictEqual({
+ ff: 'Arial',
+ });
+ expect(getMerge()).toStrictEqual([{ startRow: 0, startColumn: 0, endRow: 1, endColumn: 1 }]);
+ // redo
+ expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();
+ expect(getValue()).toStrictEqual({
+ v: 'A1',
+ });
+ expect(getMerge()).toStrictEqual([]);
});
});
@@ -214,6 +307,81 @@ describe('Test clear selection content commands', () => {
expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();
expect(getValue()).toStrictEqual({});
});
+ it('clear all with merged cells', async () => {
+ const selectionManager = get(SelectionManagerService);
+ selectionManager.setCurrentSelection({
+ pluginName: NORMAL_SELECTION_PLUGIN_NAME,
+ unitId: 'test',
+ sheetId: 'sheet1',
+ });
+ selectionManager.add([
+ {
+ range: { startRow: 0, startColumn: 0, endColumn: 1, endRow: 1, rangeType: RANGE_TYPE.NORMAL },
+ primary: null,
+ style: null,
+ },
+ ]);
+
+ function getValue(): Nullable<ICellData> {
+ return get(ICurrentUniverService)
+ .getUniverSheetInstance('test')
+ ?.getSheetBySheetId('sheet1')
+ ?.getRange(0, 0, 0, 0)
+ .getValue();
+ }
+
+ function getStyle(): Nullable<IStyleData> {
+ const value = getValue();
+ const styles = get(ICurrentUniverService).getUniverSheetInstance('test')?.getStyles();
+ if (value && styles) {
+ return styles.getStyleByCell(value);
+ }
+ }
+
+ function getMerge(): IRange[] | undefined {
+ return get(ICurrentUniverService)
+ .getUniverSheetInstance('test')
+ ?.getSheetBySheetId('sheet1')
+ ?.getConfig().mergeData;
+ }
+
+ // set formats
+ const paramsStyle: ISetRangeValuesCommandParams = {
+ value: {
+ s: {
+ ff: 'Arial',
+ },
+ },
+ };
+
+ // set style
+ expect(await commandService.executeCommand(SetRangeValuesCommand.id, paramsStyle)).toBeTruthy();
+ expect(getStyle()).toStrictEqual({
+ ff: 'Arial',
+ });
+
+ // set merge cell
+ expect(await commandService.executeCommand(AddWorksheetMergeCommand.id)).toBeTruthy();
+ expect(getMerge()).toStrictEqual([{ startRow: 0, startColumn: 0, endRow: 1, endColumn: 1 }]);
+
+ // clear all with merged cells
+ expect(await commandService.executeCommand(ClearSelectionAllCommand.id)).toBeTruthy();
+ // clear formats
+ expect(getValue()).toStrictEqual({});
+ // remove merge
+ expect(getMerge()).toStrictEqual([]);
+
+ // undo
+ expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();
+ expect(getStyle()).toStrictEqual({
+ ff: 'Arial',
+ });
+ expect(getMerge()).toStrictEqual([{ startRow: 0, startColumn: 0, endRow: 1, endColumn: 1 }]);
+ // redo
+ expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();
+ expect(getValue()).toStrictEqual({});
+ expect(getMerge()).toStrictEqual([]);
+ });
});
describe('fault situations', () => {
diff --git a/packages/base-sheets/src/commands/commands/add-worksheet-merge.command.ts b/packages/base-sheets/src/commands/commands/add-worksheet-merge.command.ts
index 57e37acc32..1bae030dc4 100644
--- a/packages/base-sheets/src/commands/commands/add-worksheet-merge.command.ts
+++ b/packages/base-sheets/src/commands/commands/add-worksheet-merge.command.ts
@@ -20,7 +20,7 @@ import {
RemoveWorksheetMergeMutation,
} from '../mutations/remove-worksheet-merge.mutation';
-interface addMergeCommandParams {
+interface IAddMergeCommandParams {
value: Dimension.ROWS | Dimension.COLUMNS;
}
@@ -28,7 +28,7 @@ export const AddWorksheetMergeCommand: ICommand = {
type: CommandType.COMMAND,
id: 'sheet.command.add-worksheet-merge',
// eslint-disable-next-line max-lines-per-function
- handler: async (accessor: IAccessor, params?: addMergeCommandParams) => {
+ handler: async (accessor: IAccessor, params?: IAddMergeCommandParams) => {
const selectionManagerService = accessor.get(SelectionManagerService);
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
diff --git a/packages/base-sheets/src/commands/commands/clear-selection-all.command.ts b/packages/base-sheets/src/commands/commands/clear-selection-all.command.ts
index d9f5f1509c..e866b4e4b2 100644
--- a/packages/base-sheets/src/commands/commands/clear-selection-all.command.ts
+++ b/packages/base-sheets/src/commands/commands/clear-selection-all.command.ts
@@ -2,16 +2,28 @@ import {
CommandType,
ICellData,
ICommand,
+ ICommandInfo,
ICommandService,
ICurrentUniverService,
IRange,
IUndoRedoService,
ObjectMatrix,
ObjectMatrixPrimitiveType,
+ Rectangle,
+ sequenceExecute,
} from '@univerjs/core';
import { IAccessor } from '@wendellhu/redi';
+import {
+ IAddWorksheetMergeMutationParams,
+ IRemoveWorksheetMergeMutationParams,
+} from '../../Basics/Interfaces/MutationInterface';
import { SelectionManagerService } from '../../services/selection-manager.service';
+import { AddWorksheetMergeMutation } from '../mutations/add-worksheet-merge.mutation';
+import {
+ RemoveMergeUndoMutationFactory,
+ RemoveWorksheetMergeMutation,
+} from '../mutations/remove-worksheet-merge.mutation';
import {
ISetRangeValuesMutationParams,
SetRangeValuesMutation,
@@ -39,6 +51,10 @@ export const ClearSelectionAllCommand: ICommand = {
return false;
}
+ const sequenceExecuteList: Array<ICommandInfo<object>> = [];
+ const sequenceExecuteUndoList: Array<ICommandInfo<object>> = [];
+
+ // clear style and content
const clearMutationParams: ISetRangeValuesMutationParams = {
range: selections,
worksheetId,
@@ -50,18 +66,56 @@ export const ClearSelectionAllCommand: ICommand = {
clearMutationParams
);
- const result = commandService.executeCommand(SetRangeValuesMutation.id, clearMutationParams);
+ sequenceExecuteList.push({
+ id: SetRangeValuesMutation.id,
+ params: clearMutationParams,
+ });
+ sequenceExecuteUndoList.push({
+ id: SetRangeValuesMutation.id,
+ params: undoClearMutationParams,
+ });
+
+ // remove merged cells
+ let hasMerge = false;
+ const mergeData = worksheet.getConfig().mergeData;
+ selections.forEach((selection) => {
+ mergeData.forEach((merge) => {
+ if (Rectangle.intersects(selection, merge)) {
+ hasMerge = true;
+ }
+ });
+ });
+
+ if (hasMerge) {
+ const removeMergeParams: IRemoveWorksheetMergeMutationParams = {
+ workbookId,
+ worksheetId,
+ ranges: selections,
+ };
+ const undoRemoveMergeParams: IAddWorksheetMergeMutationParams = RemoveMergeUndoMutationFactory(
+ accessor,
+ removeMergeParams
+ );
+
+ sequenceExecuteList.push({
+ id: RemoveWorksheetMergeMutation.id,
+ params: removeMergeParams,
+ });
+ sequenceExecuteUndoList.push({
+ id: AddWorksheetMergeMutation.id,
+ params: undoRemoveMergeParams,
+ });
+ }
+
+ const result = await sequenceExecute(sequenceExecuteList, commandService);
+
if (result) {
undoRedoService.pushUndoRedo({
// If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element.
// Hooks can be used to hook the code of external controllers to add new actions.
URI: workbookId,
- undo() {
- return commandService.executeCommand(SetRangeValuesMutation.id, undoClearMutationParams);
- },
- redo() {
- return commandService.executeCommand(SetRangeValuesMutation.id, clearMutationParams);
- },
+ undo: async () => (await sequenceExecute(sequenceExecuteUndoList, commandService)).result,
+ redo: async () => (await sequenceExecute(sequenceExecuteList, commandService)).result,
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/clear-selection-format.command.ts b/packages/base-sheets/src/commands/commands/clear-selection-format.command.ts
index 3be89ff05b..9d71cb7e45 100644
--- a/packages/base-sheets/src/commands/commands/clear-selection-format.command.ts
+++ b/packages/base-sheets/src/commands/commands/clear-selection-format.command.ts
@@ -2,16 +2,28 @@ import {
CommandType,
ICellData,
ICommand,
+ ICommandInfo,
ICommandService,
ICurrentUniverService,
IRange,
IUndoRedoService,
ObjectMatrix,
ObjectMatrixPrimitiveType,
+ Rectangle,
+ sequenceExecute,
} from '@univerjs/core';
import { IAccessor } from '@wendellhu/redi';
+import {
+ IAddWorksheetMergeMutationParams,
+ IRemoveWorksheetMergeMutationParams,
+} from '../../Basics/Interfaces/MutationInterface';
import { SelectionManagerService } from '../../services/selection-manager.service';
+import { AddWorksheetMergeMutation } from '../mutations/add-worksheet-merge.mutation';
+import {
+ RemoveMergeUndoMutationFactory,
+ RemoveWorksheetMergeMutation,
+} from '../mutations/remove-worksheet-merge.mutation';
import {
ISetRangeValuesMutationParams,
SetRangeValuesMutation,
@@ -39,6 +51,10 @@ export const ClearSelectionFormatCommand: ICommand = {
return false;
}
+ const sequenceExecuteList: Array<ICommandInfo<object>> = [];
+ const sequenceExecuteUndoList: Array<ICommandInfo<object>> = [];
+
+ // clear style
const clearMutationParams: ISetRangeValuesMutationParams = {
range: selections,
worksheetId,
@@ -50,18 +66,57 @@ export const ClearSelectionFormatCommand: ICommand = {
clearMutationParams
);
- const result = commandService.executeCommand(SetRangeValuesMutation.id, clearMutationParams);
+ sequenceExecuteList.push({
+ id: SetRangeValuesMutation.id,
+ params: clearMutationParams,
+ });
+ sequenceExecuteUndoList.push({
+ id: SetRangeValuesMutation.id,
+ params: undoClearMutationParams,
+ });
+
+ // remove merged cells
+ let hasMerge = false;
+ const mergeData = worksheet.getConfig().mergeData;
+ selections.forEach((selection) => {
+ mergeData.forEach((merge) => {
+ if (Rectangle.intersects(selection, merge)) {
+ hasMerge = true;
+ }
+ });
+ });
+
+ if (hasMerge) {
+ const removeMergeParams: IRemoveWorksheetMergeMutationParams = {
+ workbookId,
+ worksheetId,
+ ranges: selections,
+ };
+ const undoRemoveMergeParams: IAddWorksheetMergeMutationParams = RemoveMergeUndoMutationFactory(
+ accessor,
+ removeMergeParams
+ );
+
+ sequenceExecuteList.push({
+ id: RemoveWorksheetMergeMutation.id,
+ params: removeMergeParams,
+ });
+ sequenceExecuteUndoList.push({
+ id: AddWorksheetMergeMutation.id,
+ params: undoRemoveMergeParams,
+ });
+ }
+
+ const result = await sequenceExecute(sequenceExecuteList, commandService);
+
+ // const result = commandService.executeCommand(SetRangeValuesMutation.id, clearMutationParams);
if (result) {
undoRedoService.pushUndoRedo({
// If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element.
// Hooks can be used to hook the code of external controllers to add new actions.
URI: workbookId,
- undo() {
- return commandService.executeCommand(SetRangeValuesMutation.id, undoClearMutationParams);
- },
- redo() {
- return commandService.executeCommand(SetRangeValuesMutation.id, clearMutationParams);
- },
+ undo: async () => (await sequenceExecute(sequenceExecuteUndoList, commandService)).result,
+ redo: async () => (await sequenceExecute(sequenceExecuteList, commandService)).result,
});
return true;
diff --git a/packages/base-sheets/src/index.ts b/packages/base-sheets/src/index.ts
index d96121cee9..9094ebef00 100644
--- a/packages/base-sheets/src/index.ts
+++ b/packages/base-sheets/src/index.ts
@@ -23,7 +23,9 @@ export {
AddWorksheetMergeHorizontalCommand,
AddWorksheetMergeVerticalCommand,
} from './commands/commands/add-worksheet-merge.command';
+export { ClearSelectionAllCommand } from './commands/commands/clear-selection-all.command';
export { ClearSelectionContentCommand } from './commands/commands/clear-selection-content.command';
+export { ClearSelectionFormatCommand } from './commands/commands/clear-selection-format.command';
export { CopySheetCommand } from './commands/commands/copy-worksheet.command';
export { DeleteRangeMoveLeftCommand } from './commands/commands/delete-range-move-left.command';
export { DeleteRangeMoveUpCommand } from './commands/commands/delete-range-move-up.command';
diff --git a/packages/base-ui/src/Components/ColorPicker/index.module.less b/packages/base-ui/src/Components/ColorPicker/index.module.less
index 74a10f7ea0..6410ea4850 100644
--- a/packages/base-ui/src/Components/ColorPicker/index.module.less
+++ b/packages/base-ui/src/Components/ColorPicker/index.module.less
@@ -41,8 +41,8 @@
// overflow: hidden;
.picker-swatch-btn {
- width: 100%;
- height: 100%;
+ width: 20px;
+ height: 20px;
border-radius: 50%;
border: none;
cursor: pointer;
diff --git a/packages/base-ui/src/Components/Menu/Menu.tsx b/packages/base-ui/src/Components/Menu/Menu.tsx
index 8c8d5b1743..9770d8507c 100644
--- a/packages/base-ui/src/Components/Menu/Menu.tsx
+++ b/packages/base-ui/src/Components/Menu/Menu.tsx
@@ -283,6 +283,7 @@ export const Menu = (props: BaseMenuProps) => {
>
<CustomComponent
onValueChange={(v: string | number) => {
+ console.info('v=====', v);
onOptionSelect?.({
value: v,
label: option.id,
diff --git a/packages/ui-plugin-sheets/src/Locale/en.ts b/packages/ui-plugin-sheets/src/Locale/en.ts
index b63b33d0e6..8bcd04870e 100644
--- a/packages/ui-plugin-sheets/src/Locale/en.ts
+++ b/packages/ui-plugin-sheets/src/Locale/en.ts
@@ -464,6 +464,8 @@ export default {
orderAZ: 'A-Z order',
orderZA: 'Z-A order',
clearContent: 'Clear Contents',
+ clearFormat: 'Clear Formats',
+ clearAll: 'Clear All',
matrix: 'Matrix operation',
sortSelection: 'Sort',
filterSelection: 'Filter',
diff --git a/packages/ui-plugin-sheets/src/Locale/zh.ts b/packages/ui-plugin-sheets/src/Locale/zh.ts
index ccb1153a30..d6ba5e538d 100644
--- a/packages/ui-plugin-sheets/src/Locale/zh.ts
+++ b/packages/ui-plugin-sheets/src/Locale/zh.ts
@@ -327,6 +327,8 @@ export default {
orderAZ: 'A-Z顺序排列',
orderZA: 'Z-A降序排列',
clearContent: '清除内容',
+ clearFormat: '清除格式',
+ clearAll: '清除所有',
matrix: '矩阵操作选区',
sortSelection: '排序选区',
filterSelection: '筛选选区',
diff --git a/packages/ui-plugin-sheets/src/controller/menu/menu.ts b/packages/ui-plugin-sheets/src/controller/menu/menu.ts
index 7764970aaf..a35e0950e0 100644
--- a/packages/ui-plugin-sheets/src/controller/menu/menu.ts
+++ b/packages/ui-plugin-sheets/src/controller/menu/menu.ts
@@ -1,5 +1,7 @@
import {
+ ClearSelectionAllCommand,
ClearSelectionContentCommand,
+ ClearSelectionFormatCommand,
CopySheetCommand,
DeleteRangeMoveLeftCommand,
DeleteRangeMoveUpCommand,
@@ -971,7 +973,7 @@ export function PasteMenuItemFactory(): IMenuButtonItem {
// #endregion
-export function ClearSelectionMenuItemFactory(): IMenuButtonItem {
+export function ClearSelectionContentMenuItemFactory(): IMenuButtonItem {
return {
id: ClearSelectionContentCommand.id,
type: MenuItemType.BUTTON,
@@ -983,6 +985,30 @@ export function ClearSelectionMenuItemFactory(): IMenuButtonItem {
],
};
}
+export function ClearSelectionFormatMenuItemFactory(): IMenuButtonItem {
+ return {
+ id: ClearSelectionFormatCommand.id,
+ type: MenuItemType.BUTTON,
+ title: 'rightClick.clearFormat',
+ positions: [
+ MenuPosition.CONTEXT_MENU,
+ SheetMenuPosition.COL_HEADER_CONTEXT_MENU,
+ SheetMenuPosition.ROW_HEADER_CONTEXT_MENU,
+ ],
+ };
+}
+export function ClearSelectionAllMenuItemFactory(): IMenuButtonItem {
+ return {
+ id: ClearSelectionAllCommand.id,
+ type: MenuItemType.BUTTON,
+ title: 'rightClick.clearAll',
+ positions: [
+ MenuPosition.CONTEXT_MENU,
+ SheetMenuPosition.COL_HEADER_CONTEXT_MENU,
+ SheetMenuPosition.ROW_HEADER_CONTEXT_MENU,
+ ],
+ };
+}
export function InsertRowBeforeMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
const selectionManager = accessor.get(SelectionManagerService);
diff --git a/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.ts b/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.ts
index 1bbfb26669..5814563050 100644
--- a/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.ts
+++ b/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.ts
@@ -34,7 +34,9 @@ import {
BackgroundColorSelectorMenuItemFactory,
BoldMenuItemFactory,
ChangeColorSheetMenuItemFactory,
- ClearSelectionMenuItemFactory,
+ ClearSelectionAllMenuItemFactory,
+ ClearSelectionContentMenuItemFactory,
+ ClearSelectionFormatMenuItemFactory,
CONTEXT_MENU_INPUT_LABEL,
CopyMenuItemFactory,
CopySheetMenuItemFactory,
@@ -159,7 +161,9 @@ export class SheetUIController extends Disposable {
CopyMenuItemFactory,
PasteMenuItemFactory,
- ClearSelectionMenuItemFactory,
+ ClearSelectionContentMenuItemFactory,
+ ClearSelectionFormatMenuItemFactory,
+ ClearSelectionAllMenuItemFactory,
InsertRowBeforeMenuItemFactory,
InsertRowAfterMenuItemFactory,
InsertColBeforeMenuItemFactory,