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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(docs): copy table in univer (#3625)
Ran Luo8fb395fed7d5
diff --git a/packages/core/src/docs/data-model/text-x/utils.ts b/packages/core/src/docs/data-model/text-x/utils.tsindex 88f62ccfba..f1e75e0647 100644--- a/packages/core/src/docs/data-model/text-x/utils.ts+++ b/packages/core/src/docs/data-model/text-x/utils.ts@@ -14,11 +14,11 @@* limitations under the License.*/+import type { ICustomBlock, ICustomDecoration, IDocumentBody, IParagraph, ISectionBreak, ITextRun } from '../../../types/interfaces/i-document-data';+import type { IRetainAction } from './action-types';import { UpdateDocsAttributeType } from '../../../shared/command-enum';import { Tools } from '../../../shared/tools';-import type { ICustomBlock, ICustomDecoration, IDocumentBody, IParagraph, ITextRun } from '../../../types/interfaces/i-document-data';import { DataStreamTreeTokenType } from '../types';-import type { IRetainAction } from './action-types';import { coverTextRuns } from './apply-utils/update-apply';export enum SliceBodyType {@@ -35,7 +35,7 @@ export function getBodySlice(returnEmptyTextRun = false,type = SliceBodyType.cut): IDocumentBody {- const { dataStream, textRuns = [], paragraphs = [], customBlocks = [], tables = [] } = body;+ const { dataStream, textRuns = [], paragraphs = [], customBlocks = [], tables = [], sectionBreaks = [] } = body;const docBody: IDocumentBody = {dataStream: dataStream.slice(startOffset, endOffset),@@ -119,6 +119,23 @@ export function getBodySlice(startIndex: p.startIndex - startOffset,}));}++ const newSectionBreaks: ISectionBreak[] = [];++ for (const sectionBreak of sectionBreaks) {+ const { startIndex } = sectionBreak;+ if (startIndex >= startOffset && startIndex <= endOffset) {+ newSectionBreaks.push(Tools.deepClone(sectionBreak));+ }+ }++ if (newSectionBreaks.length) {+ docBody.sectionBreaks = newSectionBreaks.map((sb) => ({+ ...sb,+ startIndex: sb.startIndex - startOffset,+ }));+ }+if (type === SliceBodyType.cut) {docBody.customDecorations = getCustomDecorationSlice(body, startOffset, endOffset);}diff --git a/packages/docs-ui/src/services/clipboard/clipboard.service.ts b/packages/docs-ui/src/services/clipboard/clipboard.service.tsindex 5f19179b63..e1ec8d297b 100644--- a/packages/docs-ui/src/services/clipboard/clipboard.service.ts+++ b/packages/docs-ui/src/services/clipboard/clipboard.service.ts@@ -373,6 +373,7 @@ export class DocClipboardService extends Disposable implements IDocClipboardServconst { spanEntireRow } = range as IRectRangeWithStyle;let bodySlice: IDocumentBody;+if (!spanEntireRow) {bodySlice = getTableSlice(body, startOffset, endOffset);} else {diff --git a/packages/docs-ui/src/services/selection/convert-rect-range.ts b/packages/docs-ui/src/services/selection/convert-rect-range.tsindex d665018a6d..7ff23726e9 100644--- a/packages/docs-ui/src/services/selection/convert-rect-range.ts+++ b/packages/docs-ui/src/services/selection/convert-rect-range.ts@@ -14,9 +14,9 @@* limitations under the License.*/+import type { DocumentSkeleton, IDocumentOffsetConfig, IDocumentSkeletonGlyph, IDocumentSkeletonPage, IDocumentSkeletonRow, IDocumentSkeletonTable, INodePosition, IPoint } from '@univerjs/engine-render';import { type Nullable, Tools } from '@univerjs/core';import { DocumentSkeletonPageType, getPageFromPath, getTableIdAndSliceIndex, Liquid } from '@univerjs/engine-render';-import type { DocumentSkeleton, IDocumentOffsetConfig, IDocumentSkeletonGlyph, IDocumentSkeletonPage, IDocumentSkeletonRow, IDocumentSkeletonTable, INodePosition, IPoint } from '@univerjs/engine-render';import { compareNodePositionLogic, pushToPoints } from './convert-text-range';// The anchor and focus need to be in the same table,@@ -266,20 +266,23 @@ export class NodePositionConvertToRectRange {return;}+ for (const table of tables) {+ this._collectPositionGroup(table, nodePositionGroup, startRowIndex, endRowIndex, startColumnIndex, endColumnIndex, segmentPage, compare);+ }+const totalColumns = tables[0].rows[0].cells.length;// Span entires row.if (startColumnIndex === 0 && endColumnIndex === totalColumns - 1) {- nodePositionGroup.push({- anchor: anchorNodePosition,- focus: focusNodePosition,- });+ const firstPosition = nodePositionGroup[0];+ const lastPosition = nodePositionGroup[nodePositionGroup.length - 1];- return nodePositionGroup;- }+ nodePositionGroup.length = 0;- for (const table of tables) {- this._collectPositionGroup(table, nodePositionGroup, startRowIndex, endRowIndex, startColumnIndex, endColumnIndex, segmentPage, compare);+ nodePositionGroup.push({+ anchor: compare ? firstPosition.anchor : lastPosition.anchor,+ focus: compare ? lastPosition.focus : firstPosition.focus,+ });}return nodePositionGroup;