fix:优化元素位置获取算法
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user