退格键

This commit is contained in:
satori 2025-01-16 06:21:14 +08:00
parent 5bb61de760
commit b70a082307

View File

@ -100,6 +100,14 @@ export class Cursor {
this.insertIndex = Math.max(0, Math.min(this.targetNode.textContent.length, this.insertIndex + 1)) this.insertIndex = Math.max(0, Math.min(this.targetNode.textContent.length, this.insertIndex + 1))
return this.updatePosition(this.getBoundingClientRect()) return this.updatePosition(this.getBoundingClientRect())
} }
if (key === "Backspace") {
const text = this.targetNode.textContent
const left = text.slice(0, Math.max(0, this.insertIndex - 1))
const right = text.slice(this.insertIndex)
this.targetNode.textContent = left + right
this.insertIndex = Math.max(0, this.insertIndex - 1)
return this.updatePosition(this.getBoundingClientRect())
}
} }
} }