From 40b4db3323084ec1ee11d5a3c768f1ce9166126d Mon Sep 17 00:00:00 2001 From: evykassirer Date: Fri, 1 Mar 2024 14:33:11 -0800 Subject: [PATCH] typeahead: Refactor switch statements to avoid fallthrough. --- web/third/bootstrap-typeahead/typeahead.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/web/third/bootstrap-typeahead/typeahead.js b/web/third/bootstrap-typeahead/typeahead.js index 6990f7f1a6..cd967bb658 100644 --- a/web/third/bootstrap-typeahead/typeahead.js +++ b/web/third/bootstrap-typeahead/typeahead.js @@ -460,6 +460,9 @@ import {get_string_diff} from "../../src/util"; if (!this.options.tabIsEnter) { return; } + e.preventDefault(); + break; + case 13: // enter case 27: // escape e.preventDefault(); @@ -521,6 +524,12 @@ import {get_string_diff} from "../../src/util"; if (!this.options.tabIsEnter) { return; } + if (!this.shown) { + return; + } + this.select(e); + break; + case 13: // enter if (!this.shown) { return; @@ -538,14 +547,15 @@ import {get_string_diff} from "../../src/util"; } break; - // to stop typeahead from showing up momentarily - // when shift + tabbing to the topic field - case 16: // shift - if (e.currentTarget.id === "stream_message_recipient_topic") { + default: + // to stop typeahead from showing up momentarily + // when shift (keycode 16) + tabbing to the topic field + if ( + pseudo_keycode === 16 && + e.currentTarget.id === "stream_message_recipient_topic" + ) { return; } - - default: var hideOnEmpty = false; // backspace if (