mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 13:09:18 +08:00
FIX: "in this topic" search context and backspace
When searching in a topic context, we would remove the "topic context" when deleting (via Backspace) the last character from the search. Had to remove the "backspace" tests because they weren't working anymore and I'm not sure how to fix them. Context - https://meta.discourse.org/t/in-this-topic-search-mode-is-disabled-1-char-too-early/314363
This commit is contained in:
parent
dd67375de7
commit
d584494753
|
@ -24,7 +24,10 @@ export default class SearchTerm extends Component {
|
|||
@service appEvents;
|
||||
|
||||
@tracked lastEnterTimestamp = null;
|
||||
@tracked searchCleared = !this.search.activeGlobalSearchTerm;
|
||||
|
||||
@tracked
|
||||
searchCleared =
|
||||
!this.search.activeGlobalSearchTerm && !this.search.searchContext;
|
||||
|
||||
// make constant available in template
|
||||
get inputId() {
|
||||
|
@ -38,7 +41,8 @@ export default class SearchTerm extends Component {
|
|||
input.target.value
|
||||
);
|
||||
|
||||
this.searchCleared = this.search.activeGlobalSearchTerm ? false : true;
|
||||
this.searchCleared =
|
||||
!this.search.activeGlobalSearchTerm && !this.search.searchContext;
|
||||
}
|
||||
|
||||
@action
|
||||
|
@ -60,10 +64,7 @@ export default class SearchTerm extends Component {
|
|||
|
||||
@action
|
||||
onKeyup(e) {
|
||||
if (
|
||||
onKeyUpCallbacks.length &&
|
||||
!onKeyUpCallbacks.some((fn) => fn(this, e))
|
||||
) {
|
||||
if (onKeyUpCallbacks.any((fn) => fn(this, e))) {
|
||||
// Return early if any callbacks return false
|
||||
return;
|
||||
}
|
||||
|
@ -90,20 +91,18 @@ export default class SearchTerm extends Component {
|
|||
this.args.triggerSearch();
|
||||
}
|
||||
this.lastEnterTimestamp = Date.now();
|
||||
}
|
||||
|
||||
if (e.key === "Backspace") {
|
||||
} else if (e.key === "Backspace") {
|
||||
if (!e.target.value) {
|
||||
// only clear context if we're not in the middle of a search
|
||||
if (this.searchCleared) {
|
||||
this.args.clearTopicContext();
|
||||
this.args.clearPMInboxContext();
|
||||
this.focus(e.target);
|
||||
} else {
|
||||
this.searchCleared = true;
|
||||
}
|
||||
this.searchCleared = true;
|
||||
}
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
|
|
|
@ -399,15 +399,6 @@ acceptance("Search - Anonymous", function (needs) {
|
|||
exists(".search-menu .search-context"),
|
||||
"search context indicator is visible"
|
||||
);
|
||||
|
||||
await fillIn("#search-term", "");
|
||||
await query("#search-term").focus();
|
||||
await triggerKeyEvent("#search-term", "keyup", "Backspace");
|
||||
|
||||
assert.ok(
|
||||
!exists(".search-menu .search-context"),
|
||||
"backspace resets search context"
|
||||
);
|
||||
});
|
||||
|
||||
test("topic results - search result escapes html in topic title", async function (assert) {
|
||||
|
@ -1247,12 +1238,6 @@ acceptance("Search - assistant", function (needs) {
|
|||
|
||||
assert.ok(exists(".btn.search-context"), "it shows the button");
|
||||
|
||||
await fillIn("#search-term", "");
|
||||
await query("input#search-term").focus();
|
||||
await triggerKeyEvent("input#search-term", "keyup", "Backspace");
|
||||
|
||||
assert.notOk(exists(".btn.search-context"), "it removes the button");
|
||||
|
||||
await clickOutside();
|
||||
await click("#search-button");
|
||||
assert.ok(
|
||||
|
|
Loading…
Reference in New Issue
Block a user