feat:优化虚拟光标定位
This commit is contained in:
@@ -47,18 +47,17 @@ export class Cursor {
|
|||||||
const cursorPosition = this.draw.getPosition().getCursorPosition()
|
const cursorPosition = this.draw.getPosition().getCursorPosition()
|
||||||
if (!cursorPosition) return
|
if (!cursorPosition) return
|
||||||
// 设置光标代理
|
// 设置光标代理
|
||||||
const { lineHeight, metrics, coordinate: { rightTop } } = cursorPosition
|
const { metrics, coordinate: { leftTop, rightTop }, ascent } = cursorPosition
|
||||||
const height = metrics.fontBoundingBoxAscent + metrics.fontBoundingBoxDescent
|
const height = metrics.fontBoundingBoxAscent + metrics.fontBoundingBoxDescent
|
||||||
const agentCursorDom = this.cursorAgent.getAgentCursorDom()
|
const agentCursorDom = this.cursorAgent.getAgentCursorDom()
|
||||||
agentCursorDom.focus()
|
agentCursorDom.focus()
|
||||||
agentCursorDom.setSelectionRange(0, 0)
|
agentCursorDom.setSelectionRange(0, 0)
|
||||||
const lineBottom = rightTop[1] + lineHeight
|
|
||||||
const curosrleft = `${rightTop[0]}px`
|
const curosrleft = `${rightTop[0]}px`
|
||||||
agentCursorDom.style.left = curosrleft
|
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.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.display = 'block'
|
||||||
this.cursorDom.style.height = `${height}px`
|
this.cursorDom.style.height = `${height}px`
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ export class Draw {
|
|||||||
value: element.value,
|
value: element.value,
|
||||||
rowNo: i,
|
rowNo: i,
|
||||||
metrics,
|
metrics,
|
||||||
|
ascent: curRow.ascent,
|
||||||
lineHeight: curRow.height,
|
lineHeight: curRow.height,
|
||||||
isLastLetter: j === curRow.elementList.length - 1,
|
isLastLetter: j === curRow.elementList.length - 1,
|
||||||
coordinate: {
|
coordinate: {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export interface IElementPosition {
|
|||||||
index: number;
|
index: number;
|
||||||
value: string,
|
value: string,
|
||||||
rowNo: number;
|
rowNo: number;
|
||||||
|
ascent: number;
|
||||||
lineHeight: number;
|
lineHeight: number;
|
||||||
metrics: TextMetrics;
|
metrics: TextMetrics;
|
||||||
isLastLetter: boolean,
|
isLastLetter: boolean,
|
||||||
|
|||||||
Reference in New Issue
Block a user