mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
navbar: Only set searchbox text when displaying the searchbox.
Previously, the navbar failed at managing the searchbox text state in cases where, eg, the user performs navigation by browser history. This commit resolves the issue by ensuring that the searchbox text is only (and always) set when the searchbox is made visible, and as such there is no "state" to manage and we will always display the correct text. It also adds a test in `search_legacy.js` to make sure that the search text is placed as intended. Fixes: #14771.
This commit is contained in:
@@ -251,6 +251,7 @@ run_test('initiate_search', () => {
|
||||
// this implicitly expects the code to used the chained
|
||||
// function calls, which is something to keep in mind if
|
||||
// this test ever fails unexpectedly.
|
||||
narrow_state.filter = () => ({is_search: return_true});
|
||||
let typeahead_forced_open = false;
|
||||
let is_searchbox_text_selected = false;
|
||||
$('#search_query').select = noop;
|
||||
@@ -267,4 +268,10 @@ run_test('initiate_search', () => {
|
||||
search.initiate_search();
|
||||
assert(typeahead_forced_open);
|
||||
assert(is_searchbox_text_selected);
|
||||
assert.equal($('#search_query').val(), "ver");
|
||||
|
||||
// test that we append space for user convenience
|
||||
narrow_state.filter = () => ({is_search: return_false});
|
||||
search.initiate_search();
|
||||
assert.equal($('#search_query').val(), "ver ");
|
||||
});
|
||||
|
@@ -345,12 +345,6 @@ exports.activate = function (raw_operators, opts) {
|
||||
compose.update_closed_compose_buttons_for_stream();
|
||||
}
|
||||
|
||||
// Put the narrow operators in the search bar.
|
||||
// we append a space to make searching more convenient in some cases.
|
||||
if (filter && !filter.is_search()) {
|
||||
$('#search_query').val(Filter.unparse(operators) + " ");
|
||||
}
|
||||
|
||||
search.update_button_visibility();
|
||||
|
||||
compose_actions.on_narrow(opts);
|
||||
|
@@ -123,8 +123,12 @@ function build_tab_bar(filter) {
|
||||
// we rely entirely on this function to ensure
|
||||
// the searchbar has the right text.
|
||||
exports.reset_searchbox_text = function () {
|
||||
const search_string = narrow_state.search_string();
|
||||
let search_string = narrow_state.search_string();
|
||||
if (search_string !== "") {
|
||||
if (!page_params.search_pills_enabled && !narrow_state.filter().is_search()) {
|
||||
// saves the user a keystroke for quick searches
|
||||
search_string = search_string + " ";
|
||||
}
|
||||
$("#search_query").val(search_string);
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user