Skip to content

Commit

Permalink
feat: limit the max cursor offsetHeight #348
Browse files Browse the repository at this point in the history
Co-authored-by: xukuanzhuo <xukuanzhuo@jd.com>
Co-authored-by: Hufe921 <huangyunfeihufe@hotmail.com>
  • Loading branch information
3 people authored Dec 3, 2023
1 parent 6ca1919 commit 2666bc4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/editor/core/cursor/Cursor.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion src/editor/core/draw/Draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/editor/dataset/constant/Cursor.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 2666bc4

Please sign in to comment.