Skip to content

Commit

Permalink
fix(cell): fix cell format of rich text (#4261)
Browse files Browse the repository at this point in the history
Co-authored-by: wpxp123456 <Wpxp1223456>
  • Loading branch information
wpxp123456 authored Dec 25, 2024
1 parent a0838c5 commit 91c201a
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { Choose } from '../lookup/choose';
import { FUNCTION_NAMES_LOOKUP } from '../lookup/function-names';
import { Xlookup } from '../lookup/xlookup';
import { Xmatch } from '../lookup/xmatch';
import { Fact } from '../math/fact';
import { FUNCTION_NAMES_MATH } from '../math/function-names';
import { Product } from '../math/product';
import { Sum } from '../math/sum';
Expand Down Expand Up @@ -268,6 +269,52 @@ const getFunctionsTestWorkbookData = (): IWorkbookData => {
t: 4,
},
},
12: {
0: {
v: '10',
t: 1,
p: {
id: '__INTERNAL_EDITOR__DOCS_NORMAL',
documentStyle: {
pageSize: {
width: 73,
height: undefined,
},
marginTop: 1,
marginBottom: 2,
marginRight: 2,
marginLeft: 2,
renderConfig: {
horizontalAlign: 0,
verticalAlign: 0,
centerAngle: 0,
vertexAngle: 0,
wrapStrategy: 0,
},
},
body: {
dataStream: '10\r\n',
textRuns: [
{ ts: { ff: 'Arial', fs: 11 }, st: 0, ed: 1 },
{ st: 1, ed: 2, ts: { ff: 'Arial', fs: 11, cl: { rgb: '#B20000' } } },
],
paragraphs: [
{ startIndex: 2, paragraphStyle: { horizontalAlign: 0 } },
],
sectionBreaks: [
{ startIndex: 3 },
],
customRanges: [],
customDecorations: [],
},
drawings: {},
drawingsOrder: [],
settings: {
zoomRatio: 1,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -345,7 +392,8 @@ describe('Test nested functions', () => {
new Choose(FUNCTION_NAMES_LOOKUP.CHOOSE),
new Len(FUNCTION_NAMES_TEXT.LEN),
new Divided(FUNCTION_NAMES_META.DIVIDED),
new Product(FUNCTION_NAMES_MATH.PRODUCT)
new Product(FUNCTION_NAMES_MATH.PRODUCT),
new Fact(FUNCTION_NAMES_MATH.FACT)
);

calculate = (formula: string) => {
Expand Down Expand Up @@ -458,5 +506,15 @@ describe('Test nested functions', () => {
result = calculate('=PRODUCT("2")');
expect(result).toBe(2);
});

it('value is rich text', () => {
let result = calculate('=SUM(A13)');
expect(result).toStrictEqual(0);

result = calculate('=FACT(A13)');
expect(result).toStrictEqual([
[3628800],
]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,118 @@ describe('Test EndEditController', () => {
...target,
});
});
it('Text cell input richText', () => {
const cell: ICellData = {
s: {
n: {
pattern: '@@@',
},
},
t: 1,
v: '10',
};

const inputCell = {
p: {
id: '__INTERNAL_EDITOR__DOCS_NORMAL',
documentStyle: {
pageSize: {
width: 73,
height: undefined,
},
marginTop: 1,
marginBottom: 2,
marginRight: 2,
marginLeft: 2,
renderConfig: {
horizontalAlign: 0,
verticalAlign: 0,
centerAngle: 0,
vertexAngle: 0,
wrapStrategy: 0,
},
},
body: {
dataStream: '10\r\n',
textRuns: [
{ ts: { ff: 'Arial', fs: 11 }, st: 0, ed: 1 },
{ st: 1, ed: 2, ts: { ff: 'Arial', fs: 11, cl: { rgb: '#B20000' } } },
],
paragraphs: [
{ startIndex: 2, paragraphStyle: { horizontalAlign: 0 } },
],
sectionBreaks: [
{ startIndex: 3 },
],
customRanges: [],
customDecorations: [],
},
drawings: {},
drawingsOrder: [],
settings: {
zoomRatio: 1,
},
},
};

const cellData = getCellDataByInputCell(cell, inputCell);
const target = {
v: '10',
t: CellValueType.STRING,
s: {
n: {
pattern: '@@@',
},
},
f: null,
si: null,
p: {
id: '__INTERNAL_EDITOR__DOCS_NORMAL',
documentStyle: {
pageSize: {
width: Infinity,
height: Infinity,
},
marginTop: 0,
marginBottom: 2,
marginRight: 2,
marginLeft: 2,
renderConfig: {
horizontalAlign: 0,
verticalAlign: 0,
centerAngle: 0,
vertexAngle: 0,
wrapStrategy: 0,
zeroWidthParagraphBreak: 1,
},
},
body: {
dataStream: '10\r\n',
textRuns: [
{ ts: { ff: 'Arial', fs: 11 }, st: 0, ed: 1 },
{ st: 1, ed: 2, ts: { ff: 'Arial', fs: 11, cl: { rgb: '#B20000' } } },
],
paragraphs: [
{ startIndex: 2, paragraphStyle: { horizontalAlign: 0 } },
],
sectionBreaks: [
{ startIndex: 3 },
],
customRanges: [],
customDecorations: [],
},
drawings: {},
drawingsOrder: [],
settings: {
zoomRatio: 1,
},
},
};

expect(cellData).toEqual({
...target,
});
});
it('Rich text cell', () => {
const cell = {
v: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ export class EditingRenderController extends Disposable implements IRenderModule
}
}

// eslint-disable-next-line
export function getCellDataByInput(
cellData: ICellData,
documentDataModel: Nullable<DocumentDataModel>,
Expand Down Expand Up @@ -774,6 +775,17 @@ export function getCellDataByInput(
cellData.si = null;
cellData.p = null;
cellData.t = CellValueType.STRING;

// Text format supports rich text
if (isRichText(body) && body.dataStream !== '\r\n') {
cellData.p = snapshot;
}

// If the style length in textRun.ts is equal to the content length, it should be set as the cell style
const style = getCellStyleBySnapshot(snapshot);
if (style) {
cellData.s = style;
}
} else if (isFormulaString(newDataStream)) {
if (cellData.f === newDataStream) {
return null;
Expand Down

0 comments on commit 91c201a

Please sign in to comment.