Skip to content

Commit

Permalink
stream search: Always close search on Escape.
Browse files Browse the repository at this point in the history
  • Loading branch information
evykassirer authored and timabbott committed Nov 6, 2023
1 parent b51da3b commit 8cf4363
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
2 changes: 1 addition & 1 deletion web/src/hotkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export function process_escape_key(e) {
}

if (stream_list.searching()) {
stream_list.escape_search();
stream_list.clear_and_hide_search();
return true;
}

Expand Down
12 changes: 1 addition & 11 deletions web/src/stream_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -874,16 +874,6 @@ export function searching() {
return $(".stream-list-filter").expectOne().is(":focus");
}

export function escape_search() {
const $filter = $(".stream-list-filter").expectOne();
if ($filter.val() === "") {
clear_and_hide_search();
return;
}
$filter.val("");
update_streams_for_search();
}

export function clear_search(e) {
e.stopPropagation();
const $filter = $(".stream-list-filter").expectOne();
Expand Down Expand Up @@ -926,7 +916,7 @@ export function initiate_search() {
}

export function clear_and_hide_search() {
const $filter = $(".stream-list-filter");
const $filter = $(".stream-list-filter").expectOne();
if ($filter.val() !== "") {
$filter.val("");
update_streams_for_search();
Expand Down
11 changes: 3 additions & 8 deletions web/tests/stream_search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ run_test("basics", ({override_rewire}) => {
assert.ok($input.is_focused());
}

function verify_blurred() {
assert.ok(stream_list.searching());
assert.ok($input.is_focused());
}

function verify_collapsed() {
assert.ok($section.hasClass("notdisplayed"));
assert.ok(!$input.is_focused());
Expand Down Expand Up @@ -163,16 +158,16 @@ run_test("basics", ({override_rewire}) => {

// Escape a non-empty search.
$input.val("foo");
stream_list.escape_search();
verify_blurred();
stream_list.clear_and_hide_search();
verify_collapsed();

// Expand the widget.
toggle_filter();
stream_list.initiate_search();

// Escape an empty search.
$input.val("");
stream_list.escape_search();
stream_list.clear_and_hide_search();
verify_collapsed();
});

Expand Down

0 comments on commit 8cf4363

Please sign in to comment.