Skip to content

Commit

Permalink
fix: dragging element boundary error
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Mar 2, 2024
1 parent fdb1fbd commit a2d8dd5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/editor/core/event/CanvasEvent.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -60,6 +61,7 @@ export class CanvasEvent {
this.cacheRange = null
this.cacheElementList = null
this.cachePositionList = null
this.cachePositionContext = null
this.mouseDownStartPosition = null
}

Expand Down
1 change: 1 addition & 0 deletions src/editor/core/event/handlers/mousedown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 6 additions & 5 deletions src/editor/core/event/handlers/mouseup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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()
Expand Down Expand Up @@ -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])
// 设置拖拽值
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a2d8dd5

Please sign in to comment.