Skip to content

Commit

Permalink
fix: 1301
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs committed Jul 5, 2024
1 parent 1c6f2aa commit 28a4d43
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class DocDrawingTransformerController extends Disposable {
}

if (drawingCache && drawingCache.drawing.layoutType !== PositionedObjectLayoutType.INLINE) {
throttleNonInlineMoveUpdate(drawingCache.drawing, object, true);
// throttleNonInlineMoveUpdate(drawingCache.drawing, object, true);
}
}
})
Expand Down
56 changes: 35 additions & 21 deletions packages/docs/src/commands/commands/delete.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import type { ICommand, IDocumentBody, IMutationInfo, IParagraph, ITextRun, JSONXActions } from '@univerjs/core';
import type { ICommand, ICustomBlock, IDocumentBody, IMutationInfo, IParagraph, ITextRun, JSONXActions } from '@univerjs/core';
import {
CommandType,
ICommandService,
Expand Down Expand Up @@ -552,49 +552,63 @@ export const DeleteRightCommand: ICommand = {
},
};

function getParagraphBody(body: IDocumentBody, startIndex: number, endIndex: number): IDocumentBody {
const { textRuns: originTextRuns } = body;
const dataStream = body.dataStream.substring(startIndex, endIndex);
function getParagraphBody(body: IDocumentBody, start: number, end: number): IDocumentBody {
const { textRuns: originTextRuns = [], customBlocks: originCustomBlocks = [] } = body;
const dataStream = body.dataStream.substring(start, end);

if (originTextRuns == null) {
return {
dataStream,
};
}
const bodySlice: IDocumentBody = {
dataStream,
};

const textRuns: ITextRun[] = [];

for (const textRun of originTextRuns) {
const { st, ed } = textRun;
if (ed <= startIndex || st >= endIndex) {
if (ed <= start || st >= end) {
continue;
}

if (st < startIndex) {
if (st < start) {
textRuns.push({
...textRun,
st: 0,
ed: ed - startIndex,
ed: ed - start,
});
} else if (ed > endIndex) {
} else if (ed > end) {
textRuns.push({
...textRun,
st: st - startIndex,
ed: endIndex - startIndex,
st: st - start,
ed: end - start,
});
} else {
textRuns.push({
...textRun,
st: st - startIndex,
ed: ed - startIndex,
st: st - start,
ed: ed - start,
});
}
}

return {
dataStream,
textRuns,
};
if (textRuns.length > 0) {
bodySlice.textRuns = textRuns;
}

const customBlocks: ICustomBlock[] = [];
for (const block of originCustomBlocks) {
const { startIndex } = block;
if (startIndex >= start && startIndex <= end) {
customBlocks.push({
...block,
startIndex: startIndex - start,
});
}
}

if (customBlocks.length > 0) {
bodySlice.customBlocks = customBlocks;
}

return bodySlice;
}

// get cursor position when BACKSPACE/DELETE excuse the CutContentCommand.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ function _lineOperator(
.filter((drawing) => drawingsInLine.includes(drawing.drawingId));

if (relativeLineDrawings.length > 0) {
__updateAndPositionDrawings(ctx, preLine.top, preLine.lineHeight, column, relativeLineDrawings, preLine.paragraphIndex);
__updateAndPositionDrawings(ctx, preLine.top, preLine.lineHeight, column, relativeLineDrawings, preLine.paragraphIndex, paragraphStart);
}
}

Expand All @@ -529,7 +529,7 @@ function _lineOperator(
const targetDrawings = [...paragraphAffectSkeDrawings.values()]
.filter((drawing) => drawing.drawingOrigin.docTransform.positionV.relativeFrom !== ObjectRelativeFromV.LINE);

__updateAndPositionDrawings(ctx, lineTop, lineHeight, column, targetDrawings, paragraphConfig.paragraphIndex, drawingAnchor?.get(paragraphIndex)?.top);
__updateAndPositionDrawings(ctx, lineTop, lineHeight, column, targetDrawings, paragraphConfig.paragraphIndex, paragraphStart, drawingAnchor?.get(paragraphIndex)?.top);
}

const newLineTop = calculateLineTopByDrawings(
Expand Down Expand Up @@ -611,6 +611,7 @@ function __updateAndPositionDrawings(
column: IDocumentSkeletonColumn,
targetDrawings: IDocumentSkeletonDrawing[],
paragraphIndex: number,
paragraphStart: boolean,
drawingAnchorTop?: number
) {
if (targetDrawings.length === 0) {
Expand All @@ -621,6 +622,7 @@ function __updateAndPositionDrawings(
lineTop,
lineHeight,
column,
paragraphStart,
drawingAnchorTop,
targetDrawings
);
Expand Down Expand Up @@ -1008,6 +1010,7 @@ function __getDrawingPosition(
lineTop: number,
lineHeight: number,
column: IDocumentSkeletonColumn,
paragraphStart: boolean,
blockAnchorTop?: number,
needPositionDrawings: IDocumentSkeletonDrawing[] = []
) {
Expand All @@ -1022,8 +1025,8 @@ function __getDrawingPosition(
const drawings: Map<string, IDocumentSkeletonDrawing> = new Map();
const isPageBreak = __checkPageBreak(column);

// TODO: @jocs 在跨页场景,默认将 drawing 放到上一页,下一页不处理 drawing?
if (isPageBreak) {
// TODO: @jocs 在段落跨页场景(一个段落在两页),默认将 drawing 放到上一页,下一页不处理 drawing?
if (isPageBreak && !paragraphStart) {
return;
}

Expand Down

0 comments on commit 28a4d43

Please sign in to comment.