diff --git a/cursor.js b/cursor.js index f6afd9f..91e29b4 100644 --- a/cursor.js +++ b/cursor.js @@ -100,6 +100,14 @@ export class Cursor { this.insertIndex = Math.max(0, Math.min(this.targetNode.textContent.length, this.insertIndex + 1)) 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()) + } } }