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