mirror of https://github.com/zulip/zulip.git
typeahead: Pass query to highlighter_html instead of using hacky this.
This commit is contained in:
parent
cf9cf14dde
commit
9fc6793809
|
@ -193,7 +193,7 @@ class Typeahead<ItemType extends string | object> {
|
|||
items: number;
|
||||
matcher: (item: ItemType, query: string) => boolean;
|
||||
sorter: (items: ItemType[]) => ItemType[];
|
||||
highlighter_html: (item: ItemType) => string | undefined;
|
||||
highlighter_html: (item: ItemType, query: string) => string | undefined;
|
||||
updater: (
|
||||
item: ItemType,
|
||||
event?: JQuery.ClickEvent | JQuery.KeyUpEvent | JQuery.KeyDownEvent,
|
||||
|
@ -404,7 +404,7 @@ class Typeahead<ItemType extends string | object> {
|
|||
render(final_items: ItemType[], matching_items: ItemType[]): this {
|
||||
const $items: JQuery[] = final_items.map((item) => {
|
||||
const $i = $(ITEM_HTML).data("typeahead-value", item);
|
||||
const item_html = this.highlighter_html(item) ?? "";
|
||||
const item_html = this.highlighter_html(item, this.query) ?? "";
|
||||
const $item_html = $i.find("a").html(item_html);
|
||||
|
||||
const option_label_html = this.option_label(matching_items, item);
|
||||
|
@ -688,7 +688,7 @@ class Typeahead<ItemType extends string | object> {
|
|||
* =========================== */
|
||||
|
||||
type TypeaheadOptions<ItemType> = {
|
||||
highlighter_html: (item: ItemType) => string | undefined;
|
||||
highlighter_html: (item: ItemType, query: string) => string | undefined;
|
||||
items: number;
|
||||
source: (query: string) => ItemType[];
|
||||
// optional options
|
||||
|
|
|
@ -65,8 +65,8 @@ export function set_up($input, pills, opts) {
|
|||
}
|
||||
return source;
|
||||
},
|
||||
highlighter_html(item) {
|
||||
if (include_streams(this.query)) {
|
||||
highlighter_html(item, query) {
|
||||
if (include_streams(query)) {
|
||||
return typeahead_helper.render_stream(item);
|
||||
}
|
||||
|
||||
|
|
|
@ -160,7 +160,7 @@ run_test("set_up", ({mock_template, override}) => {
|
|||
if (opts.stream) {
|
||||
// Test stream highlighter_html for widgets that allow stream pills.
|
||||
assert.equal(
|
||||
config.highlighter_html.call(fake_stream_this, denmark),
|
||||
config.highlighter_html(denmark, fake_stream_this.query),
|
||||
$fake_rendered_stream,
|
||||
);
|
||||
}
|
||||
|
@ -168,23 +168,23 @@ run_test("set_up", ({mock_template, override}) => {
|
|||
// If user is also allowed along with user_group
|
||||
// then we should check that each of them rendered correctly.
|
||||
assert.equal(
|
||||
config.highlighter_html.call(fake_group_this, testers),
|
||||
config.highlighter_html(testers, fake_group_this.query),
|
||||
$fake_rendered_group,
|
||||
);
|
||||
assert.equal(
|
||||
config.highlighter_html.call(fake_person_this, me),
|
||||
config.highlighter_html(me, fake_person_this.query),
|
||||
$fake_rendered_person,
|
||||
);
|
||||
}
|
||||
if (opts.user && !opts.user_group) {
|
||||
assert.equal(
|
||||
config.highlighter_html.call(fake_person_this, me),
|
||||
config.highlighter_html(me, fake_person_this.query),
|
||||
$fake_rendered_person,
|
||||
);
|
||||
}
|
||||
if (!opts.user && opts.user_group) {
|
||||
assert.equal(
|
||||
config.highlighter_html.call(fake_group_this, testers),
|
||||
config.highlighter_html(testers, fake_group_this.query),
|
||||
$fake_rendered_group,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue