Skip to content

Commit 7ada185

Browse files
committed
clamp position
1 parent 6b1246a commit 7ada185

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/text-expander-element.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ class TextExpander {
103103
}
104104

105105
private positionMenu(menu: HTMLElement, position: number) {
106-
const caretRect = new InputRange(this.input, position).getBoundingClientRect()
106+
// Clamp position to valid range to avoid IndexSizeError when input text changes
107+
const clampedPosition = Math.min(position, this.input.value.length)
108+
const caretRect = new InputRange(this.input, clampedPosition).getBoundingClientRect()
107109
const targetPosition = {left: caretRect.left, top: caretRect.top + caretRect.height}
108110

109111
const currentPosition = menu.getBoundingClientRect()

0 commit comments

Comments
 (0)