fix:处理边界问题
This commit is contained in:
@@ -41,7 +41,7 @@ export class Cursor {
|
||||
agentCursorDom.focus()
|
||||
agentCursorDom.setSelectionRange(0, 0)
|
||||
})
|
||||
// fillText位置 + 文字基线到底部距离 - 模拟光标偏移量
|
||||
// fillText位置 + 文字基线到底部距离 - 模拟光标偏移量
|
||||
const descent = metrics.boundingBoxDescent < 0 ? 0 : metrics.boundingBoxDescent
|
||||
const cursorTop = (leftTop[1] + ascent) + descent - (cursorHeight - offsetHeight)
|
||||
const curosrleft = rightTop[0]
|
||||
|
||||
@@ -163,6 +163,7 @@ export class Draw {
|
||||
this.position.setPositionList([])
|
||||
const positionList = this.position.getPositionList()
|
||||
// 基础信息
|
||||
const { defaultSize } = this.options
|
||||
const canvasRect = this.canvas.getBoundingClientRect()
|
||||
// 绘制背景
|
||||
this.background.render(canvasRect)
|
||||
@@ -180,7 +181,7 @@ export class Draw {
|
||||
height: 0,
|
||||
ascent: 0,
|
||||
elementList: [],
|
||||
rowFlex: this.elementList?.[1].rowFlex
|
||||
rowFlex: this.elementList?.[1]?.rowFlex
|
||||
})
|
||||
}
|
||||
for (let i = 0; i < this.elementList.length; i++) {
|
||||
@@ -212,7 +213,7 @@ export class Draw {
|
||||
this.ctx.font = this.getFont(element)
|
||||
const fontMetrics = this.ctx.measureText(element.value)
|
||||
metrics.width = fontMetrics.width
|
||||
metrics.boundingBoxAscent = fontMetrics.actualBoundingBoxAscent
|
||||
metrics.boundingBoxAscent = i === 0 ? defaultSize : fontMetrics.actualBoundingBoxAscent
|
||||
metrics.boundingBoxDescent = fontMetrics.actualBoundingBoxDescent
|
||||
}
|
||||
const ascent = metrics.boundingBoxAscent + rowMargin
|
||||
@@ -342,7 +343,9 @@ export class Draw {
|
||||
if (isSubmitHistory) {
|
||||
const self = this
|
||||
const oldElementList = deepClone(this.elementList)
|
||||
const { startIndex, endIndex } = this.range.getRange()
|
||||
this.historyManager.execute(function () {
|
||||
self.range.setRange(startIndex, endIndex)
|
||||
self.elementList = deepClone(oldElementList)
|
||||
self.render({ curIndex, isSubmitHistory: false })
|
||||
})
|
||||
|
||||
@@ -245,7 +245,7 @@ export class CanvasEvent {
|
||||
|
||||
public paste(evt: ClipboardEvent) {
|
||||
const text = evt.clipboardData?.getData('text')
|
||||
this.input(text || '')
|
||||
this.input(text?.replaceAll(`\n`, ZERO) || '')
|
||||
evt.preventDefault()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ export default class Editor {
|
||||
canvas.height = parseInt(canvas.style.height) * dpr
|
||||
canvas.style.cursor = 'text'
|
||||
ctx.scale(dpr, dpr)
|
||||
if (elementList[0].value !== ZERO) {
|
||||
if (elementList[0]?.value !== ZERO) {
|
||||
elementList.unshift({
|
||||
value: ZERO
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user