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: inline style undo error at the doc end #2241

Merged
merged 2 commits into from
May 16, 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
14 changes: 7 additions & 7 deletions examples/src/data/docs/default-document-data-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export const DEFAULT_DOCUMENT_DATA_CN: IDocumentData = {
},
{
st: 14,
ed: 3057,
ed: 3064,
ts: {
fs: 12,
ff: 'Microsoft YaHei',
Expand Down Expand Up @@ -703,12 +703,12 @@ export const DEFAULT_DOCUMENT_DATA_CN: IDocumentData = {
sectionBreaks: [
{
startIndex: 3066,
columnProperties: [
{
width: ptToPixel(240),
paddingEnd: ptToPixel(15),
},
],
// columnProperties: [
// {
// width: ptToPixel(240),
// paddingEnd: ptToPixel(15),
// },
// ],
columnSeparatorType: ColumnSeparatorType.NONE,
sectionType: SectionType.SECTION_TYPE_UNSPECIFIED,
// textDirection: textDirectionDocument,
Expand Down
4 changes: 2 additions & 2 deletions examples/src/docs/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { UniverImagePlugin } from '@univerjs/image';

import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';

import { DEFAULT_DOCUMENT_DATA_EN } from '../data';
import { DEFAULT_DOCUMENT_DATA_CN } from '../data';

import { DebuggerPlugin } from '../plugins/debugger';

Expand Down Expand Up @@ -67,7 +67,7 @@ univer.registerPlugin(UniverDocsUIPlugin, {

univer.registerPlugin(UniverImagePlugin);

univer.createUniverDoc(DEFAULT_DOCUMENT_DATA_EN);
univer.createUniverDoc(DEFAULT_DOCUMENT_DATA_CN);

// use for console test
declare global {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('test case in apply utils', () => {
it('the inserted textRun is between two testRuns', async () => {
const removedTextRuns = deleteTextRuns(body as IDocumentBody, 10, 20);

expect(removedTextRuns.length).toBe(0);
expect(removedTextRuns.length).toBe(1);
expect(body?.textRuns![2].st).toBe(20);
expect(body?.textRuns![2].ed).toBe(30);
});
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/docs/data-model/apply-utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ export function insertCustomRanges(
}
}

// eslint-disable-next-line max-lines-per-function
export function deleteTextRuns(body: IDocumentBody, textLength: number, currentIndex: number) {
const { textRuns } = body;
const startIndex = currentIndex;
Expand Down Expand Up @@ -454,6 +455,16 @@ export function deleteTextRuns(body: IDocumentBody, textLength: number, currentI
body.textRuns = newTextRuns;
}

// In the case of no style before, add the style, removeTextRuns will be empty,
// in this case, you need to add an empty textRun for undo.
if (removeTextRuns.length === 0) {
removeTextRuns.push({
st: 0,
ed: textLength,
ts: {},
});
}

return removeTextRuns;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function updateTextRuns(
return removeTextRuns;
}

// eslint-disable-next-line max-lines-per-function
export function coverTextRuns(
updateDataTextRuns: ITextRun[],
removeTextRuns: ITextRun[],
Expand Down
Loading