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: mult rows need to be pasted into multiple cells (#4319)

ybzky17a92a865f7f
diff --git a/packages/sheets-ui/src/controllers/clipboard/utils.ts b/packages/sheets-ui/src/controllers/clipboard/utils.ts
index a4be6bdfd3..2e9b767fc1 100644
--- a/packages/sheets-ui/src/controllers/clipboard/utils.ts
+++ b/packages/sheets-ui/src/controllers/clipboard/utils.ts
@@ -41,6 +41,7 @@ import {
SheetInterceptorService,
} from '@univerjs/sheets';
import { COPY_TYPE } from '../../services/clipboard/type';
+import { isRichText } from '../editor/editing.render-controller';
import { discreteRangeToRange, type IDiscreteRange, virtualizeDiscreteRanges } from '../utils/range-tools';
// if special paste need append mutations instead of replace the default, it can use this function to generate default mutations.
@@ -313,11 +314,8 @@ export function getSetCellValueMutations(
}
const { row: realRow, col: realCol } = mapFunc(row, col);
- if (value.p?.body) {
+ if (value.p?.body && isRichText(value.p.body)) {
const newValue = Tools.deepClone({ p: value.p, v: originNumberValue ?? value.v });
- if (newValue.p.body?.textRuns) {
- newValue.p.body.textRuns = [];
- }
valueMatrix.setValue(realRow, realCol, newValue);
} else {
valueMatrix.setValue(realRow, realCol, Tools.deepClone({ v: originNumberValue ?? value.v, t: value.t }));
@@ -420,9 +418,6 @@ export function getSetCellStyleMutations(
cl: null,
}, value.s),
};
- if (withRichFormat && value.p?.body) {
- newValue.p = value.p;
- }
const content = String(value.v);
const numfmtValue = numfmt.parseValue(content);
if (numfmtValue?.z) {
diff --git a/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts b/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts
index ba2d697217..79a5ffda5c 100644
--- a/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts
+++ b/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+/* eslint-disable complexity */
+
import type { ICustomRange, IDocumentBody, IDocumentData, ITextRun, ITextStyle, Nullable } from '@univerjs/core';
import type { SpreadsheetSkeleton } from '@univerjs/engine-render';
import type { ISheetSkeletonManagerParam } from '../../sheet-skeleton-manager.service';
@@ -248,7 +250,6 @@ export class HtmlToUSMService {
return css;
}
- // eslint-disable-next-line complexity
private _getStyle(node: HTMLElement, styleStr: string) {
const recordStyle: Record<string, string> = turnToStyleObject(styleStr);
const style = node.style;
@@ -551,6 +552,12 @@ export class HtmlToUSMService {
}
} else if (skipParseTagNames.includes(node.nodeName.toLowerCase())) {
continue;
+ } else if (node.nodeName.toLowerCase() === 'br') {
+ if (!doc.paragraphs) {
+ doc.paragraphs = [];
+ }
+ doc.paragraphs.push({ startIndex: doc.dataStream.length });
+ doc.dataStream += '\r';
} else if (node.nodeType === Node.ELEMENT_NODE) {
if (node.nodeName === 'STYLE') {
continue;