From 7d46aa014c20dff0f3b9a1c18c98fae4770fd17c Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Wed, 17 Nov 2021 20:21:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BC=98=E5=8C=96=E8=99=9A=E6=8B=9F?= =?UTF-8?q?=E5=85=89=E6=A0=87=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/editor/core/cursor/Cursor.ts | 7 +++---- src/editor/core/draw/Draw.ts | 1 + src/editor/interface/Element.ts | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/editor/core/cursor/Cursor.ts b/src/editor/core/cursor/Cursor.ts index c9859a0..fa6b6e9 100644 --- a/src/editor/core/cursor/Cursor.ts +++ b/src/editor/core/cursor/Cursor.ts @@ -47,18 +47,17 @@ export class Cursor { const cursorPosition = this.draw.getPosition().getCursorPosition() if (!cursorPosition) return // 设置光标代理 - const { lineHeight, metrics, coordinate: { rightTop } } = cursorPosition + const { metrics, coordinate: { leftTop, rightTop }, ascent } = cursorPosition const height = metrics.fontBoundingBoxAscent + metrics.fontBoundingBoxDescent const agentCursorDom = this.cursorAgent.getAgentCursorDom() agentCursorDom.focus() agentCursorDom.setSelectionRange(0, 0) - const lineBottom = rightTop[1] + lineHeight const curosrleft = `${rightTop[0]}px` agentCursorDom.style.left = curosrleft - agentCursorDom.style.top = `${lineBottom - 12}px` + agentCursorDom.style.top = `${leftTop[1] + ascent - 12}px` // 模拟光标显示 this.cursorDom.style.left = curosrleft - this.cursorDom.style.top = `${lineBottom - height}px` + this.cursorDom.style.top = `${leftTop[1] + ascent - metrics.fontBoundingBoxAscent}px` this.cursorDom.style.display = 'block' this.cursorDom.style.height = `${height}px` setTimeout(() => { diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index 983901e..190eff6 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -183,6 +183,7 @@ export class Draw { value: element.value, rowNo: i, metrics, + ascent: curRow.ascent, lineHeight: curRow.height, isLastLetter: j === curRow.elementList.length - 1, coordinate: { diff --git a/src/editor/interface/Element.ts b/src/editor/interface/Element.ts index b034eb2..77e1fe3 100644 --- a/src/editor/interface/Element.ts +++ b/src/editor/interface/Element.ts @@ -21,6 +21,7 @@ export interface IElementPosition { index: number; value: string, rowNo: number; + ascent: number; lineHeight: number; metrics: TextMetrics; isLastLetter: boolean,