From a2d8dd55b36a09b42fae377e06bf667dced3857e Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Sat, 2 Mar 2024 22:19:29 +0800 Subject: [PATCH] fix: dragging element boundary error --- src/editor/core/event/CanvasEvent.ts | 4 +++- src/editor/core/event/handlers/mousedown.ts | 1 + src/editor/core/event/handlers/mouseup.ts | 11 ++++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/editor/core/event/CanvasEvent.ts b/src/editor/core/event/CanvasEvent.ts index 09455bc..d20598d 100644 --- a/src/editor/core/event/CanvasEvent.ts +++ b/src/editor/core/event/CanvasEvent.ts @@ -1,6 +1,6 @@ import { ElementStyleKey } from '../../dataset/enum/ElementStyle' import { IElement, IElementPosition } from '../../interface/Element' -import { ICurrentPosition } from '../../interface/Position' +import { ICurrentPosition, IPositionContext } from '../../interface/Position' import { Draw } from '../draw/Draw' import { Position } from '../position/Position' import { RangeManager } from '../range/RangeManager' @@ -37,6 +37,7 @@ export class CanvasEvent { public cacheRange: IRange | null public cacheElementList: IElement[] | null public cachePositionList: IElementPosition[] | null + public cachePositionContext: IPositionContext | null public mouseDownStartPosition: ICurrentPosition | null private draw: Draw @@ -60,6 +61,7 @@ export class CanvasEvent { this.cacheRange = null this.cacheElementList = null this.cachePositionList = null + this.cachePositionContext = null this.mouseDownStartPosition = null } diff --git a/src/editor/core/event/handlers/mousedown.ts b/src/editor/core/event/handlers/mousedown.ts index ec8d32f..8ba08c4 100644 --- a/src/editor/core/event/handlers/mousedown.ts +++ b/src/editor/core/event/handlers/mousedown.ts @@ -15,6 +15,7 @@ export function setRangeCache(host: CanvasEvent) { host.cacheRange = deepClone(rangeManager.getRange()) host.cacheElementList = draw.getElementList() host.cachePositionList = position.getPositionList() + host.cachePositionContext = position.getPositionContext() } export function mousedown(evt: MouseEvent, host: CanvasEvent) { diff --git a/src/editor/core/event/handlers/mouseup.ts b/src/editor/core/event/handlers/mouseup.ts index 8d45e6c..1731fc8 100644 --- a/src/editor/core/event/handlers/mouseup.ts +++ b/src/editor/core/event/handlers/mouseup.ts @@ -51,6 +51,7 @@ export function mouseup(evt: MouseEvent, host: CanvasEvent) { if (draw.isReadonly()) return const position = draw.getPosition() const positionList = position.getPositionList() + const positionContext = position.getPositionContext() const rangeManager = draw.getRange() const cacheRange = host.cacheRange! const cacheElementList = host.cacheElementList! @@ -66,7 +67,8 @@ export function mouseup(evt: MouseEvent, host: CanvasEvent) { // 是否需要拖拽-位置发生改变 if ( range.startIndex >= cacheStartIndex && - range.endIndex <= cacheEndIndex + range.endIndex <= cacheEndIndex && + host.cachePositionContext?.tdId === positionContext.tdId ) { // 清除渲染副作用 draw.clearSideEffect() @@ -159,7 +161,9 @@ export function mouseup(evt: MouseEvent, host: CanvasEvent) { } }) formatElementContext(elementList, replaceElementList, range.startIndex) - // 缓存拖拽选区开始结束id + // 缓存拖拽选区开始元素、位置、开始结束id + const cacheStartElement = cacheElementList[cacheStartIndex] + const cacheStartPosition = cachePositionList[cacheStartIndex] const cacheRangeStartId = createDragId(cacheElementList[cacheStartIndex]) const cacheRangeEndId = createDragId(cacheElementList[cacheEndIndex]) // 设置拖拽值 @@ -220,10 +224,7 @@ export function mouseup(evt: MouseEvent, host: CanvasEvent) { } // 重设上下文 const startElement = elementList[range.startIndex] - const cacheStartElement = cacheElementList[cacheStartIndex] const startPosition = positionList[range.startIndex] - const cacheStartPosition = cachePositionList[cacheStartIndex] - const positionContext = position.getPositionContext() let positionContextIndex = positionContext.index if (positionContextIndex) { if (startElement.tableId && !cacheStartElement.tableId) {