fix(copy): fix copy id (#6469)

This commit is contained in:
wpxp123456
2026-01-15 15:42:47 +08:00
committed by GitHub
parent 905faee8e4
commit bf75a44faf
3 changed files with 6 additions and 7 deletions
@@ -150,7 +150,7 @@ describe('Test clipboard', () => {
})).toBeTruthy();
const { html, copyId } = sheetClipboardService.generateCopyContent('test', 'sheet1', selection.range)!;
const result = `<google data-copy-id="${copyId}"-sheets-html-origin><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none"><colgroup><col width="88" /></colgroup>
const result = `<google-sheets-html-origin><table data-copy-id="${copyId}" xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none"><colgroup><col width="88" /></colgroup>
<tbody><tr style="height: 24px;"><td style="font-size: 20pt; color: #ff0000; border-bottom: 0.5pt solid #000000; border-top: 0.5pt solid #000000; border-right: 0.5pt solid #000000; border-left: 0.5pt solid #000000; ">1</td></tr><tr style="height: 24px;"><td style="font-size: 20pt; color: #ff0000; border-bottom: 0.5pt solid #000000; border-top: 0.5pt solid #000000; border-right: 0.5pt solid #000000; border-left: 0.5pt solid #000000; ">2</td></tr><tr style="height: 24px;"><td style="font-size: 20pt; color: #ff0000; border-bottom: 0.5pt solid #000000; border-top: 0.5pt solid #000000; border-right: 0.5pt solid #000000; border-left: 0.5pt solid #000000; ">3</td></tr><tr style="height: 24px;"><td style="font-size: 20pt; color: #ff0000; border-bottom: 0.5pt solid #000000; border-top: 0.5pt solid #000000; border-right: 0.5pt solid #000000; border-left: 0.5pt solid #000000; ">4</td></tr></tbody></table>`;
expect(html).toBe(result);
});
@@ -495,11 +495,9 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
}
// convert matrix to html
let html = this._usmToHtml.convert(matrix, discreteRange, hooks);
const plain = getMatrixPlainText(plainMatrix);
const copyId = genId();
html = html.replace(/(<[a-z]+)/, (_p0, p1) => `${p1} data-copy-id="${copyId}"`);
const html = this._usmToHtml.convert(matrix, discreteRange, hooks, copyId);
const plain = getMatrixPlainText(plainMatrix);
return {
copyId,
@@ -121,7 +121,8 @@ export class USMToHtmlService {
}
>,
range: IDiscreteRange,
hooks: ISheetClipboardHook[]
hooks: ISheetClipboardHook[],
copyId?: string
): string {
const { cols, rows } = range;
if (!cols.length) {
@@ -135,7 +136,7 @@ export class USMToHtmlService {
rowContents.push(getRowContent(row, cols, hooks, matrix, mergeSet));
});
const html = `<google-sheets-html-origin><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none">${colStyles}
const html = `<google-sheets-html-origin><table data-copy-id="${copyId}" xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none">${colStyles}
<tbody>${rowContents.join('')}</tbody></table>`;
return html;
}