Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cell): fix cell format of rich text #4261

Merged
merged 3 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading