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: fix the cut menu item in the context menu (#6280)

wpxp12345640d5d24acdd3
diff --git a/packages/sheets-ui/src/controllers/clipboard/utils.ts b/packages/sheets-ui/src/controllers/clipboard/utils.ts
index 94f9e3242f..3c3ac1256e 100644
--- a/packages/sheets-ui/src/controllers/clipboard/utils.ts
+++ b/packages/sheets-ui/src/controllers/clipboard/utils.ts
@@ -49,6 +49,7 @@ import {
AddMergeUndoMutationFactory,
AddWorksheetMergeMutation,
getAddMergeMutationRangeByType,
+ getPrimaryForRange,
MoveRangeCommand,
MoveRangeMutation,
RemoveMergeUndoMutationFactory,
@@ -222,72 +223,76 @@ export function getMoveRangeMutations(
const toMergeData = toWorksheet.getMergeData();
const fromMergeRanges = fromMergeData.filter((item) => Rectangle.intersects(item, fromRange));
const toMergeRanges = toMergeData.filter((item) => Rectangle.intersects(item, toRange));
-
- const willMoveToMergeRanges = fromMergeRanges
- .map((mergeRange) => Rectangle.getRelativeRange(mergeRange, fromRange))
- .map((relativeRange) => Rectangle.getPositionRange(relativeRange, toRange));
-
- const addMergeCellRanges = getAddMergeMutationRangeByType(willMoveToMergeRanges);
-
const mergeRedos: Array<{
id: string;
params: IAddWorksheetMergeMutationParams | IRemoveWorksheetMergeMutationParams;
- }> = [
- {
- id: RemoveWorksheetMergeMutation.id,
- params: {
- unitId,
- subUnitId: fromSubUnitId,
- ranges: fromMergeRanges,
- },
- },
- {
- id: RemoveWorksheetMergeMutation.id,
- params: {
- unitId,
- subUnitId: fromSubUnitId,
- ranges: toMergeRanges,
- },
- },
- {
- id: AddWorksheetMergeMutation.id,
- params: {
- unitId,
- subUnitId: toSubUnitId,
- ranges: addMergeCellRanges,
- },
- },
- ];
+ }> = [];
const mergeUndos: Array<{
id: string;
params: IAddWorksheetMergeMutationParams | IRemoveWorksheetMergeMutationParams;
- }> = [
- {
- id: RemoveWorksheetMergeMutation.id,
+ }> = [];
+
+ if (fromMergeRanges.length > 0 || toMergeRanges.length > 0) {
+ const willMoveToMergeRanges = fromMergeRanges
+ .map((mergeRange) => Rectangle.getRelativeRange(mergeRange, fromRange))
+ .map((relativeRange) => Rectangle.getPositionRange(relativeRange, toRange));
+ const addMergeCellRanges = getAddMergeMutationRangeByType(willMoveToMergeRanges);
+
+ if (fromMergeRanges.length > 0) {
+ mergeRedos.push({
+ id: RemoveWorksheetMergeMutation.id,
+ params: {
+ unitId,
+ subUnitId: fromSubUnitId,
+ ranges: fromMergeRanges,
+ },
+ });
+ mergeUndos.push({
+ id: AddWorksheetMergeMutation.id,
+ params: {
+ unitId,
+ subUnitId: fromSubUnitId,
+ ranges: fromMergeRanges,
+ },
+ });
+ }
+
+ if (toMergeRanges.length > 0) {
+ mergeRedos.push({
+ id: RemoveWorksheetMergeMutation.id,
+ params: {
+ unitId,
+ subUnitId: fromSubUnitId,
+ ranges: toMergeRanges,
+ },
+ });
+ mergeUndos.push({
+ id: AddWorksheetMergeMutation.id,
+ params: {
+ unitId,
+ subUnitId: toSubUnitId,
+ ranges: toMergeRanges,
+ },
+ });
+ }
+
+ mergeRedos.push({
+ id: AddWorksheetMergeMutation.id,
params: {
unitId,
subUnitId: toSubUnitId,
ranges: addMergeCellRanges,
},
- },
- {
- id: AddWorksheetMergeMutation.id,
+ });
+ mergeUndos.unshift({
+ id: RemoveWorksheetMergeMutation.id,
params: {
unitId,
subUnitId: toSubUnitId,
- ranges: toMergeRanges,
- },
- },
- {
- id: AddWorksheetMergeMutation.id,
- params: {
- unitId,
- subUnitId: fromSubUnitId,
- ranges: fromMergeRanges,
+ ranges: addMergeCellRanges,
},
- },
- ];
- // +++++++++++++++++++++
+ });
+ }
redos = [
{ id: MoveRangeMutation.id, params: doMoveRangeMutation },
@@ -298,7 +303,7 @@ export function getMoveRangeMutations(
params: {
unitId,
subUnitId: toSubUnitId,
- selections: [{ range: toRange }],
+ selections: [{ range: toRange, primary: getPrimaryForRange(toRange, toWorksheet) }],
type: SelectionMoveType.MOVE_END,
} as ISetSelectionsOperationParams,
},
@@ -313,7 +318,7 @@ export function getMoveRangeMutations(
unitId,
subUnitId: fromSubUnitId,
type: SelectionMoveType.MOVE_END,
- selections: [{ range: fromRange }],
+ selections: [{ range: fromRange, primary: getPrimaryForRange(fromRange, fromWorksheet) }],
},
},
];
diff --git a/packages/sheets-ui/src/controllers/menu.schema.ts b/packages/sheets-ui/src/controllers/menu.schema.ts
index 814810fdf9..299ed2f8c4 100644
--- a/packages/sheets-ui/src/controllers/menu.schema.ts
+++ b/packages/sheets-ui/src/controllers/menu.schema.ts
@@ -52,7 +52,7 @@ import {
import { ContextMenuGroup, ContextMenuPosition, RibbonPosition, RibbonStartGroup } from '@univerjs/ui';
import {
SheetCopyCommand,
- // SheetCutCommand,
+ SheetCutCommand,
SheetPasteBesidesBorderCommand,
SheetPasteColWidthCommand,
SheetPasteCommand,
@@ -118,7 +118,7 @@ import {
CancelFrozenMenuItemFactory,
ColAutoWidthMenuItemFactory,
CopyMenuItemFactory,
- // CutMenuItemFactory,
+ CutMenuItemFactory,
FitContentMenuItemFactory,
FontFamilySelectorMenuItemFactory,
FormatPainterMenuItemFactory,
@@ -294,10 +294,10 @@ export const menuSchema: MenuSchemaType = {
order: 0,
menuItemFactory: CopyMenuItemFactory,
},
- // [SheetCutCommand.name]: {
- // order: 1,
- // menuItemFactory: CutMenuItemFactory,
- // },
+ [SheetCutCommand.name]: {
+ order: 1,
+ menuItemFactory: CutMenuItemFactory,
+ },
[SheetPasteCommand.name]: {
order: 2,
menuItemFactory: PasteMenuItemFactory,
@@ -435,10 +435,10 @@ export const menuSchema: MenuSchemaType = {
order: 0,
menuItemFactory: CopyMenuItemFactory,
},
- // [SheetCutCommand.name]: {
- // order: 1,
- // menuItemFactory: CutMenuItemFactory,
- // },
+ [SheetCutCommand.name]: {
+ order: 1,
+ menuItemFactory: CutMenuItemFactory,
+ },
[SheetPasteCommand.name]: {
order: 2,
menuItemFactory: PasteMenuItemFactory,
@@ -556,10 +556,10 @@ export const menuSchema: MenuSchemaType = {
order: 0,
menuItemFactory: CopyMenuItemFactory,
},
- // [SheetCutCommand.name]: {
- // order: 1,
- // menuItemFactory: CutMenuItemFactory,
- // },
+ [SheetCutCommand.name]: {
+ order: 1,
+ menuItemFactory: CutMenuItemFactory,
+ },
[SheetPasteCommand.name]: {
order: 2,
menuItemFactory: PasteMenuItemFactory,
diff --git a/packages/sheets-ui/src/controllers/menu/menu.ts b/packages/sheets-ui/src/controllers/menu/menu.ts
index 85d5b01cef..fbb3ce260f 100644
--- a/packages/sheets-ui/src/controllers/menu/menu.ts
+++ b/packages/sheets-ui/src/controllers/menu/menu.ts
@@ -911,11 +911,12 @@ export function CutMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
id: SheetCutCommand.name,
commandId: CutCommand.id,
type: MenuItemType.BUTTON,
- title: 'contextMenu.cut',
+ title: 'rightClick.cut',
+ icon: 'CutIcon',
disabled$: getCurrentRangeDisable$(accessor, {
- workbookTypes: [WorkbookEditablePermission],
- rangeTypes: [RangeProtectionPermissionEditPoint],
+ workbookTypes: [WorkbookCopyPermission, WorkbookEditablePermission],
worksheetTypes: [WorksheetCopyPermission, WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionViewPoint, RangeProtectionPermissionEditPoint],
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
};
diff --git a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
index e9b4bbf02e..ceef6496a4 100644
--- a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
+++ b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
@@ -810,9 +810,11 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
});
// setting the selection should be done separately, regardless of the pasting type.
- const setSelectionOperation = this._getSetSelectionOperation(unitId, subUnitId, pastedRange, cellMatrix, pasteType);
- if (setSelectionOperation) {
- redoMutationsInfo.push(setSelectionOperation);
+ if (payload.copyType === COPY_TYPE.COPY) {
+ const setSelectionOperation = this._getSetSelectionOperation(unitId, subUnitId, pastedRange, cellMatrix, pasteType);
+ if (setSelectionOperation) {
+ redoMutationsInfo.push(setSelectionOperation);
+ }
}
redoMutationsInfo = mergeSetRangeValues(redoMutationsInfo);
diff --git a/packages/ui/src/common/component-manager.ts b/packages/ui/src/common/component-manager.ts
index 40f396274e..0f36962751 100644
--- a/packages/ui/src/common/component-manager.ts
+++ b/packages/ui/src/common/component-manager.ts
@@ -42,6 +42,7 @@ import {
CodeIcon,
ConditionsDoubleIcon,
CopyDoubleIcon,
+ CutIcon,
DeleteCellMoveDownDoubleIcon,
DeleteCellShiftLeftDoubleIcon,
DeleteCellShiftRightDoubleIcon,
@@ -169,6 +170,7 @@ const iconList: Record<string, ForwardRefExoticComponent<any>> = {
CodeIcon,
ConditionsDoubleIcon,
CopyDoubleIcon,
+ CutIcon,
DeleteCellMoveDownDoubleIcon,
DeleteCellShiftLeftDoubleIcon,
DeleteCellShiftRightDoubleIcon,