feat: limit the max cursor offsetHeight #348

Co-authored-by: xukuanzhuo <xukuanzhuo@jd.com>
Co-authored-by: Hufe921 <huangyunfeihufe@hotmail.com>
pr675
KZ Xu 2 years ago committed by GitHub
parent 6ca1919498
commit 2666bc43c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,4 +1,4 @@
import { CURSOR_AGENT_HEIGHT } from '../../dataset/constant/Cursor'
import { CURSOR_AGENT_OFFSET_HEIGHT } from '../../dataset/constant/Cursor'
import { EDITOR_PREFIX } from '../../dataset/constant/Editor'
import { MoveDirection } from '../../dataset/enum/Observer'
import { DeepRequired } from '../../interface/Common'
@ -121,9 +121,11 @@ export class Cursor {
? pageNo
: this.draw.getPageNo()
const preY = curPageNo * (height + pageGap)
// 增加1/4字体大小
const offsetHeight = metrics.height / 4
const cursorHeight = metrics.height + offsetHeight * 2
// 默认偏移高度
const defaultOffsetHeight = CURSOR_AGENT_OFFSET_HEIGHT * scale
// 增加1/4字体大小最小为defaultOffsetHeight即默认偏移高度
const increaseHeight = Math.min(metrics.height / 4, defaultOffsetHeight)
const cursorHeight = metrics.height + increaseHeight * 2
const agentCursorDom = this.cursorAgent.getAgentCursorDom()
if (isFocus) {
setTimeout(() => {
@ -135,16 +137,16 @@ export class Cursor {
const descent =
metrics.boundingBoxDescent < 0 ? 0 : metrics.boundingBoxDescent
const cursorTop =
leftTop[1] + ascent + descent - (cursorHeight - offsetHeight) + preY
leftTop[1] + ascent + descent - (cursorHeight - increaseHeight) + preY
const cursorLeft = hitLineStartIndex ? leftTop[0] : rightTop[0]
agentCursorDom.style.left = `${cursorLeft}px`
agentCursorDom.style.top = `${
cursorTop + cursorHeight - CURSOR_AGENT_HEIGHT * scale
cursorTop + cursorHeight - defaultOffsetHeight
}px`
// 模拟光标显示
if (!isShow) return
const isReadonly = this.draw.isReadonly()
this.cursorDom.style.width = `${width}px`
this.cursorDom.style.width = `${width * scale}px`
this.cursorDom.style.backgroundColor = color
this.cursorDom.style.left = `${cursorLeft}px`
this.cursorDom.style.top = `${cursorTop}px`

@ -1194,7 +1194,7 @@ export class Draw {
metrics.width = elementWidth
metrics.height = elementHeight
metrics.boundingBoxDescent = elementHeight
metrics.boundingBoxAscent = 0
metrics.boundingBoxAscent = -rowMargin
// 表格分页处理(拆分表格)
const height = this.getHeight()
const marginHeight = this.getMainOuterHeight()

@ -1,6 +1,6 @@
import { ICursorOption } from '../../interface/Cursor'
export const CURSOR_AGENT_HEIGHT = 12
export const CURSOR_AGENT_OFFSET_HEIGHT = 12
export const defaultCursorOption: Readonly<Required<ICursorOption>> = {
width: 1,

Loading…
Cancel
Save