fix: dragging element boundary error
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user