diff --git a/examples/index.html b/examples/index.html index 2cd56e0..d1152ad 100644 --- a/examples/index.html +++ b/examples/index.html @@ -30,12 +30,51 @@

Multiword text-expander element

+

Multiword and multikey text-expander element

+ + + + +

Multiword and multikey text-expander element with random delay

+ + + + diff --git a/src/text-expander-element.ts b/src/text-expander-element.ts index dcb0126..1801eee 100644 --- a/src/text-expander-element.ts +++ b/src/text-expander-element.ts @@ -201,6 +201,10 @@ class TextExpander { this.justPasted = true } + private isMatchStillValid(match: TextExpanderMatch): boolean { + return match.position <= this.input.value.length + } + async onInput() { if (this.justPasted) { this.justPasted = false @@ -213,7 +217,11 @@ class TextExpander { const menu = await this.notifyProviders(match) // Text was cleared while waiting on async providers. - if (!this.match) return + if (!this.match || !this.isMatchStillValid(match)) { + this.match = null + this.deactivate() + return + } if (menu) { this.activate(match, menu)