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): can not paste content when have both text range and rect range (#3720)

Ran Luo3cfcf7ec5e21
diff --git a/packages/core/src/shared/clipboard.ts b/packages/core/src/shared/clipboard.ts
index e2f616b37e..8dd11e7a98 100644
--- a/packages/core/src/shared/clipboard.ts
+++ b/packages/core/src/shared/clipboard.ts
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import { BaselineOffset, BooleanNumber } from '../types/enum';
import type { IDocumentBody, ITextRun } from '../types/interfaces';
+import { BaselineOffset, BooleanNumber } from '../types/enum';
import { Tools } from './tools';
export function getBodySliceHtml(body: IDocumentBody, startIndex: number, endIndex: number) {
diff --git a/packages/docs-ui/src/commands/commands/clipboard.inner.command.ts b/packages/docs-ui/src/commands/commands/clipboard.inner.command.ts
index 80f60c6b6a..19366ca2d5 100644
--- a/packages/docs-ui/src/commands/commands/clipboard.inner.command.ts
+++ b/packages/docs-ui/src/commands/commands/clipboard.inner.command.ts
@@ -14,18 +14,6 @@
* limitations under the License.
*/
-import {
- BuildTextUtils,
- CommandType,
- ICommandService,
- IUniverInstanceService,
- JSONX,
- MemoryCursor,
- TextX,
- TextXActionType,
- Tools,
-} from '@univerjs/core';
-import { DocSelectionManagerService, RichTextEditingMutation } from '@univerjs/docs';
import type {
DocumentDataModel,
ICommand,
@@ -38,6 +26,18 @@ import type {
} from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '@univerjs/docs';
import type { DocumentViewModel, IRectRangeWithStyle, ITextRangeWithStyle } from '@univerjs/engine-render';
+import {
+ BuildTextUtils,
+ CommandType,
+ ICommandService,
+ IUniverInstanceService,
+ JSONX,
+ MemoryCursor,
+ TextX,
+ TextXActionType,
+ Tools,
+} from '@univerjs/core';
+import { DocSelectionManagerService, RichTextEditingMutation } from '@univerjs/docs';
import { getCommandSkeleton, getRichTextEditPath } from '../util';
import { getDeleteRowContentActionParams, getDeleteRowsActionsParams, getDeleteTableActionParams } from './table/table';
@@ -90,6 +90,7 @@ export const InnerPasteCommand: ICommand<IInnerPasteCommandParams> = {
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const originSelections = docSelectionManagerService.getTextRanges();
+ const rectRanges = docSelectionManagerService.getRectRanges();
const { body, tableSource, drawings } = doc;
if (!Array.isArray(originSelections) || originSelections.length === 0 || body == null) {
return false;
@@ -135,6 +136,11 @@ export const InnerPasteCommand: ICommand<IInnerPasteCommandParams> = {
return false;
}
+ // Can not paste content when doc selection has both text ranges and rect ranges.
+ if (selections.length && rectRanges?.length) {
+ return false;
+ }
+
for (const selection of selections) {
const { startOffset, endOffset, collapsed } = selection;