mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
typeahead: Avoid tracebacks due to navbar changes.
In our recent navbar changes, we made it so that the
Esc key auto-closed the navbar. Unfortunately,
that code would break other typeaheads with a traceback.
One user-facing symptom was that if you drafted a PM
and started a typeahead on a recipient, then hitting
the Esc key wouldn't close the typeahead.
Now we use an `on_escape` mechanism that is specific
to the navbar typeahead, so that it's both generic and
harder to break for widgets that don't opt in to it.
See bbdc66a214 for
more details on the commit that introduced this
regression.
Note that I only call `tab_bar.exit_search` now.
I don't check the class name of the input element,
since I know that the Esc key is happening in the
context of search. And I don't blur the input,
since it's going to be hidden.
This commit is contained in:
@@ -112,6 +112,10 @@ exports.initialize = function () {
|
|||||||
},
|
},
|
||||||
stopAdvance: page_params.search_pills_enabled,
|
stopAdvance: page_params.search_pills_enabled,
|
||||||
advanceKeyCodes: [8],
|
advanceKeyCodes: [8],
|
||||||
|
|
||||||
|
// Use our custom typeahead `on_escape` hook to exit
|
||||||
|
// the search bar as soon as the user hits Esc.
|
||||||
|
on_escape: tab_bar.exit_search,
|
||||||
});
|
});
|
||||||
|
|
||||||
searchbox_form.on('compositionend', function () {
|
searchbox_form.on('compositionend', function () {
|
||||||
|
|||||||
@@ -50,13 +50,11 @@
|
|||||||
* in compose.scss and splitting $container out of $menu so we can insert
|
* in compose.scss and splitting $container out of $menu so we can insert
|
||||||
* additional HTML before $menu.
|
* additional HTML before $menu.
|
||||||
*
|
*
|
||||||
* 4. Navbar changes:
|
* 4. Escape hooks:
|
||||||
*
|
*
|
||||||
* Typically, typeahead hotkey actions are independent of other application
|
* You can set an on_escape hook to take extra actions when the user hits
|
||||||
* actions, however, the navbar is one case where we want to try and do more
|
* the `Esc` key. We use this in our navbar code to close the navbar when
|
||||||
* than a simple typeahead action with a single hotkey press, and so we've
|
* a user hits escape while in the typeahead.
|
||||||
* been forced to make a custom modification, see inline comment at `Esc`
|
|
||||||
* keyup for more details.
|
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
|
|
||||||
!function($){
|
!function($){
|
||||||
@@ -83,6 +81,7 @@
|
|||||||
this.fixed = this.options.fixed || false;
|
this.fixed = this.options.fixed || false;
|
||||||
this.automated = this.options.automated || this.automated;
|
this.automated = this.options.automated || this.automated;
|
||||||
this.trigger_selection = this.options.trigger_selection || this.trigger_selection;
|
this.trigger_selection = this.options.trigger_selection || this.trigger_selection;
|
||||||
|
this.on_escape = this.options.on_escape;
|
||||||
this.header = this.options.header || this.header;
|
this.header = this.options.header || this.header;
|
||||||
|
|
||||||
if (this.fixed) {
|
if (this.fixed) {
|
||||||
@@ -356,14 +355,10 @@
|
|||||||
|
|
||||||
case 27: // escape
|
case 27: // escape
|
||||||
if (!this.shown) return
|
if (!this.shown) return
|
||||||
// Custom Zulip code to achieve the following goals:
|
|
||||||
// when the searchbox is open in the navbar, and the typeahead is open, a single `Esc` should
|
|
||||||
// be able to close both the searchbox and the typeahead.
|
|
||||||
if ($("input:focus,textarea:focus")[0].className === "search-query input-block-level") {
|
|
||||||
tab_bar.exit_search();
|
|
||||||
$("input:focus,textarea:focus").blur();
|
|
||||||
}
|
|
||||||
this.hide()
|
this.hide()
|
||||||
|
if (this.on_escape) {
|
||||||
|
this.on_escape();
|
||||||
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user