fix:优化元素位置获取算法

pr675
黄云飞 4 years ago
parent 45c98fc1c5
commit 0529c03ec7

@ -59,7 +59,7 @@ export class Draw {
this.listener = listener
this.historyManager = new HistoryManager()
this.position = new Position(this)
this.position = new Position(options, this)
this.range = new RangeManager(ctx, options, this)
this.margin = new Margin(ctx, options)
this.background = new Background(ctx)

@ -1,5 +1,6 @@
import { ElementType } from "../.."
import { ZERO } from "../../dataset/constant/Common"
import { IEditorOption } from "../../interface/Editor"
import { IElement, IElementPosition } from "../../interface/Element"
import { ICurrentPosition } from "../../interface/Position"
import { Draw } from "../draw/Draw"
@ -11,12 +12,14 @@ export class Position {
private elementList: IElement[]
private draw: Draw
private options: Required<IEditorOption>
constructor(draw: Draw) {
constructor(options: Required<IEditorOption>, draw: Draw) {
this.positionList = []
this.elementList = []
this.cursorPosition = null
this.options = options
this.draw = draw
}
@ -66,7 +69,14 @@ export class Position {
for (let j = 0; j < firstLetterList.length; j++) {
const { index, coordinate: { leftTop, leftBottom } } = firstLetterList[j]
if (y > leftTop[1] && y <= leftBottom[1]) {
const isHead = x < this.options.margins[3]
// 是否在头部
if (isHead) {
const headIndex = this.positionList.findIndex(p => p.rowNo === firstLetterList[j].rowNo)
curPostionIndex = ~headIndex ? headIndex : index
} else {
curPostionIndex = index
}
isLastArea = true
break
}

Loading…
Cancel
Save