mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 17:36:27 +00:00
search: Open typeahead on empty string only if lookup triggered by Tab.
Fixes part of #10026. Adds additional option to typeahead: `tabOpensEmptyTypeahead`(default: false): tabOpensEmptyTypeahead overrides helpOnEmptyStrings. This commit sets helpOnEmptyStrings to false and tabOpensEmptyTypeahead to true. Now typeahead will open on an empty string only if Tab has been pressed.
This commit is contained in:
committed by
Tim Abbott
parent
0e2c509a24
commit
b961093c14
@@ -89,7 +89,8 @@ run_test('initizalize', () => {
|
|||||||
assert.equal(opts.fixed, true);
|
assert.equal(opts.fixed, true);
|
||||||
assert.equal(opts.items, 12);
|
assert.equal(opts.items, 12);
|
||||||
assert.equal(opts.naturalSearch, true);
|
assert.equal(opts.naturalSearch, true);
|
||||||
assert.equal(opts.helpOnEmptyStrings, true);
|
assert.equal(opts.tabOpensEmptyTypeahead, true);
|
||||||
|
assert.equal(opts.helpOnEmptyStrings, false);
|
||||||
assert.equal(opts.matcher(), true);
|
assert.equal(opts.matcher(), true);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ exports.initialize = function () {
|
|||||||
// just represents the key of the hash, so it's redundant.)
|
// just represents the key of the hash, so it's redundant.)
|
||||||
var search_object = {};
|
var search_object = {};
|
||||||
|
|
||||||
|
// tabOpensEmptyTypeahead overrides helpOnEmptyStrings.
|
||||||
search_query_box.typeahead({
|
search_query_box.typeahead({
|
||||||
source: function (query) {
|
source: function (query) {
|
||||||
var suggestions;
|
var suggestions;
|
||||||
@@ -86,7 +87,8 @@ exports.initialize = function () {
|
|||||||
},
|
},
|
||||||
fixed: true,
|
fixed: true,
|
||||||
items: 12,
|
items: 12,
|
||||||
helpOnEmptyStrings: true,
|
tabOpensEmptyTypeahead: page_params.search_pills_enabled,
|
||||||
|
helpOnEmptyStrings: !page_params.search_pills_enabled,
|
||||||
naturalSearch: true,
|
naturalSearch: true,
|
||||||
highlighter: function (item) {
|
highlighter: function (item) {
|
||||||
var obj = search_object[item];
|
var obj = search_object[item];
|
||||||
|
|||||||
7
static/third/bootstrap/js/bootstrap.js
vendored
7
static/third/bootstrap/js/bootstrap.js
vendored
@@ -1900,10 +1900,10 @@
|
|||||||
|
|
||||||
, lookup: function (event) {
|
, lookup: function (event) {
|
||||||
var items
|
var items
|
||||||
|
var from_tab = (event === 'from_tab')
|
||||||
|
|
||||||
this.query = this.$element.is("[contenteditable]") ? this.$element.text() : this.$element.val();
|
this.query = this.$element.is("[contenteditable]") ? this.$element.text() : this.$element.val();
|
||||||
|
if (!this.options.helpOnEmptyStrings && !(from_tab && this.options.tabOpensEmptyTypeahead)) {
|
||||||
if (!this.options.helpOnEmptyStrings) {
|
|
||||||
if (!this.query || this.query.length < this.options.minLength) {
|
if (!this.query || this.query.length < this.options.minLength) {
|
||||||
return this.shown ? this.hide() : this
|
return this.shown ? this.hide() : this
|
||||||
}
|
}
|
||||||
@@ -2070,7 +2070,7 @@
|
|||||||
|
|
||||||
case 9: // tab
|
case 9: // tab
|
||||||
if (!this.shown) {
|
if (!this.shown) {
|
||||||
this.lookup()
|
this.lookup('from_tab')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.select(e)
|
this.select(e)
|
||||||
@@ -2143,6 +2143,7 @@
|
|||||||
, stopAdvance: false
|
, stopAdvance: false
|
||||||
, dropup: false
|
, dropup: false
|
||||||
, advanceKeyCodes: []
|
, advanceKeyCodes: []
|
||||||
|
, tabOpensEmptyTypeahead: false
|
||||||
}
|
}
|
||||||
|
|
||||||
$.fn.typeahead.Constructor = Typeahead
|
$.fn.typeahead.Constructor = Typeahead
|
||||||
|
|||||||
Reference in New Issue
Block a user