search: Bold search operands in the first search result.

Specifically when it's the last operand of the search
filter. This makes the first line of search results
more consistent with the lines that come after.
This commit is contained in:
evykassirer
2023-06-29 19:47:15 -04:00
committed by Tim Abbott
parent 8f5305a4ce
commit d293e869bd
2 changed files with 12 additions and 5 deletions

View File

@@ -749,7 +749,16 @@ export function get_search_result(query) {
// `has` and `is` operators work only on predefined categories. Default suggestion
// is not displayed in that case. e.g. `messages that contain abc` as
// a suggestion for `has:abc`does not make sense.
if (last.operator !== "" && last.operator !== "has" && last.operator !== "is") {
if (last.operator === "search") {
suggestion = {
search_string: last.operand,
description_html: `search for <strong>${Handlebars.Utils.escapeExpression(
last.operand,
)}</strong>`,
};
attacher.prepend_base(suggestion);
attacher.push(suggestion);
} else if (last.operator !== "" && last.operator !== "has" && last.operator !== "is") {
suggestion = get_default_suggestion(search_operators);
attacher.push(suggestion);
}

View File

@@ -79,9 +79,7 @@ function test(label, f) {
});
}
test("basic_get_suggestions", ({override, mock_template}) => {
mock_template("search_description.hbs", true, (data, html) => html);
test("basic_get_suggestions", ({override}) => {
const query = "fred";
override(narrow_state, "stream", () => "office");
@@ -717,7 +715,7 @@ test("topic_suggestions", ({override, mock_template}) => {
function describe(q) {
return suggestions.lookup_table.get(q).description_html;
}
assert.equal(describe("te"), "Search for te");
assert.equal(describe("te"), "Search for <strong>te</strong>");
assert.equal(describe("stream:office topic:team"), "Stream office > team");
suggestions = get_suggestions("topic:staplers stream:office");