Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

search: Use e.key instead of deprecated e.which.

Priyank Patela218143db7ff
diff --git a/frontend_tests/node_tests/search.js b/frontend_tests/node_tests/search.js
index ef317854c38..ba143cb602d 100644
--- a/frontend_tests/node_tests/search.js
+++ b/frontend_tests/node_tests/search.js
@@ -228,7 +228,7 @@ test("initialize", () => {
let default_prevented = false;
let ev = {
type: "keydown",
- which: 15,
+ key: "a",
preventDefault() {
default_prevented = true;
},
@@ -237,11 +237,11 @@ test("initialize", () => {
assert.equal(keydown(ev), undefined);
assert(!default_prevented);
- ev.which = 13;
+ ev.key = "Enter";
assert.equal(keydown(ev), undefined);
assert(!default_prevented);
- ev.which = 13;
+ ev.key = "Enter";
search_query_box.is = () => true;
assert.equal(keydown(ev), undefined);
assert(default_prevented);
@@ -288,14 +288,14 @@ test("initialize", () => {
assert(!is_blurred);
assert(!search_button.prop("disabled"));
- ev.which = 13;
+ ev.key = "Enter";
search_query_box.is = () => false;
searchbox_form.trigger(ev);
assert(!is_blurred);
assert(!search_button.prop("disabled"));
- ev.which = 13;
+ ev.key = "Enter";
search_query_box.is = () => true;
searchbox_form.trigger(ev);
assert(is_blurred);
@@ -308,7 +308,7 @@ test("initialize", () => {
assert(!search_button.prop("disabled"));
_setup("ver");
- ev.which = 13;
+ ev.key = "Enter";
search_query_box.is = () => true;
searchbox_form.trigger(ev);
assert(is_blurred);
diff --git a/frontend_tests/node_tests/search_legacy.js b/frontend_tests/node_tests/search_legacy.js
index 6f8a1457798..c64b07af32b 100644
--- a/frontend_tests/node_tests/search_legacy.js
+++ b/frontend_tests/node_tests/search_legacy.js
@@ -192,11 +192,11 @@ run_test("initialize", () => {
assert.equal(keydown(ev), undefined);
assert(!default_prevented);
- ev.which = 13;
+ ev.key = "Enter";
assert.equal(keydown(ev), undefined);
assert(!default_prevented);
- ev.which = 13;
+ ev.key = "Enter";
search_query_box.is = () => true;
assert.equal(keydown(ev), undefined);
assert(default_prevented);
@@ -235,21 +235,21 @@ run_test("initialize", () => {
];
_setup("");
- ev.which = 15;
+ ev.key = "a";
search_query_box.is = () => false;
searchbox_form.trigger(ev);
assert(!is_blurred);
assert(!search_button.prop("disabled"));
- ev.which = 13;
+ ev.key = "Enter";
search_query_box.is = () => false;
searchbox_form.trigger(ev);
assert(!is_blurred);
assert(!search_button.prop("disabled"));
- ev.which = 13;
+ ev.key = "Enter";
search_query_box.is = () => true;
searchbox_form.trigger(ev);
assert(is_blurred);
@@ -262,7 +262,7 @@ run_test("initialize", () => {
assert(!search_button.prop("disabled"));
_setup("ver");
- ev.which = 13;
+ ev.key = "Enter";
search_query_box.is = () => true;
searchbox_form.trigger(ev);
assert(is_blurred);
diff --git a/static/js/search.js b/static/js/search.js
index 6121ff9dbc2..11457bc377d 100644
--- a/static/js/search.js
+++ b/static/js/search.js
@@ -134,8 +134,7 @@ export function initialize() {
searchbox_form
.on("keydown", (e) => {
update_button_visibility();
- const code = e.which;
- if (code === 13 && search_query_box.is(":focus")) {
+ if (e.key === "Enter" && search_query_box.is(":focus")) {
// Don't submit the form so that the typeahead can instead
// handle our Enter keypress. Any searching that needs
// to be done will be handled in the keyup.
@@ -147,8 +146,8 @@ export function initialize() {
is_using_input_method = false;
return;
}
- const code = e.which;
- if (code === 13 && search_query_box.is(":focus")) {
+
+ if (e.key === "Enter" && search_query_box.is(":focus")) {
// We just pressed Enter and the box had focus, which
// means we didn't use the typeahead at all. In that
// case, we should act as though we're searching by