From 5201d5792d0555c1390af9fb5a748062067a2c91 Mon Sep 17 00:00:00 2001 From: Chanakya Bhardwaj Date: Tue, 24 Nov 2020 12:18:35 +0100 Subject: [PATCH] Revert "Small clean up for deactivation check." This reverts commit cd81b9a36b6f2c951c29ab7bff4e2e71ded18c7b. --- src/text-expander-element.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/text-expander-element.ts b/src/text-expander-element.ts index 83965b0..a734831 100644 --- a/src/text-expander-element.ts +++ b/src/text-expander-element.ts @@ -88,9 +88,9 @@ class TextExpander { this.combobox.navigate(1) } - deactivate(cursor: number): boolean { + deactivate(cursor: number) { const menu = this.menu - if (!menu || !this.combobox) return false + if (!menu || !this.combobox) return this.menu = null menu.removeEventListener('combobox-commit', this.oncommit) @@ -102,7 +102,6 @@ class TextExpander { menu.remove() this.lookBackIndex = cursor - return true } onDismiss() { @@ -209,11 +208,13 @@ class TextExpander { } onKeydown(event: KeyboardEvent) { - if (event.key === 'Escape') { - if (this.deactivate(this.input.selectionEnd || this.lookBackIndex)) { - event.stopImmediatePropagation() - event.preventDefault() + if (event.key === 'Escape' && (this.menu || this.combobox)) { + const cancelled = this.expander.dispatchEvent(new CustomEvent('text-expander-dismiss', {cancelable: true})) + if (cancelled) { + return } + event.stopImmediatePropagation() + event.preventDefault() } } }