From 0529c03ec7fb12e9c7952a28beaa768ede79192c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BA=91=E9=A3=9E?= Date: Mon, 22 Nov 2021 20:19:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BC=98=E5=8C=96=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E8=8E=B7=E5=8F=96=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/editor/core/draw/Draw.ts | 2 +- src/editor/core/position/Position.ts | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index b4ac4ff..d97096a 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -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) diff --git a/src/editor/core/position/Position.ts b/src/editor/core/position/Position.ts index 602aa5a..6a77981 100644 --- a/src/editor/core/position/Position.ts +++ b/src/editor/core/position/Position.ts @@ -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 - constructor(draw: Draw) { + constructor(options: Required, 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]) { - curPostionIndex = index + 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 }