From 6d2cda4308a54d8e6d027219940d0eee49f5051e Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Fri, 23 Aug 2024 06:55:01 +0000 Subject: [PATCH] typeahead: Remove patch for IME enter events. Key value for IME enter keypress is "Process", so we don't need to patch it here. --- web/src/bootstrap_typeahead.ts | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/web/src/bootstrap_typeahead.ts b/web/src/bootstrap_typeahead.ts index 8941a28470..0038e65142 100644 --- a/web/src/bootstrap_typeahead.ts +++ b/web/src/bootstrap_typeahead.ts @@ -75,12 +75,6 @@ * If typeahead would go off the top of the screen, we set its top to 0 instead. * This patch should be replaced with something more flexible. * - * 7. Ignore IME Enter events: - * - * See #22062 for details. Enter keypress that are part of IME composing are - * treated as a separate/invalid -13 key, to prevent them from being incorrectly - * processed as a bonus Enter press. - * * 8. Make the typeahead completions undo friendly: * * We now use the undo supporting `insert` function from the @@ -173,17 +167,6 @@ import * as tippy from "tippy.js"; import * as scroll_util from "./scroll_util"; import {get_string_diff, the} from "./util"; -function get_pseudo_key( - event: JQuery.KeyDownEvent | JQuery.KeyUpEvent | JQuery.KeyPressEvent, -): string { - const isComposing = event.originalEvent?.isComposing ?? false; - /* Ignore IME compose enter keypresses. (See 7 above) */ - if (event.code === "Enter" && isComposing) { - return "IgnoreEnter"; - } - return event.key; -} - export function defaultSorter(items: string[], query: string): string[] { const beginswith = []; const caseSensitive = []; @@ -650,9 +633,8 @@ export class Typeahead { } maybeStopAdvance(e: JQuery.KeyPressEvent | JQuery.KeyUpEvent | JQuery.KeyDownEvent): void { - const pseudo_key = get_pseudo_key(e); if ( - (this.stopAdvance || (pseudo_key !== "Tab" && pseudo_key !== "Enter")) && + (this.stopAdvance || (e.key !== "Tab" && e.key !== "Enter")) && !this.advanceKeys.includes(e.key) ) { e.stopPropagation(); @@ -663,9 +645,8 @@ export class Typeahead { if (!this.shown) { return; } - const pseudo_key = get_pseudo_key(e); - switch (pseudo_key) { + switch (e.key) { case "Tab": if (!this.tabIsEnter) { return; @@ -702,7 +683,6 @@ export class Typeahead { } keydown(e: JQuery.KeyDownEvent): void { - const pseudo_key = get_pseudo_key(e); if (this.trigger_selection(e)) { if (!this.shown) { return; @@ -711,7 +691,7 @@ export class Typeahead { this.select(e); } this.suppressKeyPressRepeat = !["ArrowDown", "ArrowUp", "Tab", "Enter", "Escape"].includes( - pseudo_key, + e.key, ); this.move(e); } @@ -731,9 +711,7 @@ export class Typeahead { // it did modify the query. For example, `Command + delete` on Mac // doesn't trigger a keyup event but when `Command` is released, it // triggers a keyup event which correctly updates the list. - const pseudo_key = get_pseudo_key(e); - - switch (pseudo_key) { + switch (e.key) { case "ArrowDown": case "ArrowUp": break; @@ -777,7 +755,7 @@ export class Typeahead { // to stop typeahead from showing up momentarily // when shift + tabbing to the topic field if ( - pseudo_key === "Shift" && + e.key === "Shift" && the(this.input_element.$element).id === "stream_message_recipient_topic" ) { return; @@ -789,7 +767,7 @@ export class Typeahead { // the search bar). this.openInputFieldOnKeyUp(); } - if (pseudo_key === "Backspace") { + if (e.key === "Backspace") { this.lookup(this.hideOnEmptyAfterBackspace); return; }