Skip to content

Commit

Permalink
fix: inline style undo error at the doc end
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs committed May 14, 2024
1 parent 2739fba commit 63de045
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
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
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

0 comments on commit 63de045

Please sign in to comment.