Skip to content

Commit f497e76

Browse files
authored
fix: AI search runs even when toggle is hidden (microsoft#255496)
1 parent 190ec36 commit f497e76

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ export class SettingsEditor2 extends EditorPane {
774774
}
775775

776776
toggleAiSearch(): void {
777-
if (this.showAiResultsAction) {
777+
if (this.searchInputActionBar && this.showAiResultsAction && this.searchInputActionBar.hasAction(this.showAiResultsAction)) {
778778
if (!this.showAiResultsAction.enabled) {
779779
aria.status(localize('noAiResults', "No AI results available at this time."));
780780
}
@@ -1824,23 +1824,27 @@ export class SettingsEditor2 extends EditorPane {
18241824
return;
18251825
}
18261826

1827-
// Kick off an AI search in the background. We purposely do not await it.
18281827
if (this.aiSearchPromise) {
18291828
this.aiSearchPromise.cancel();
18301829
}
1831-
this.aiSearchPromise = createCancelablePromise(token => {
1832-
return this.doAiSearch(query, token).then((results) => {
1833-
if (results && this.showAiResultsAction) {
1834-
this.showAiResultsAction.enabled = true;
1835-
this.showAiResultsAction.label = SHOW_AI_RESULTS_ENABLED_LABEL;
1836-
this.renderResultCountMessages(true);
1837-
}
1838-
}).catch(e => {
1839-
if (!isCancellationError(e)) {
1840-
this.logService.trace('Error during AI settings search:', e);
1841-
}
1830+
1831+
// Kick off an AI search in the background if the toggle is shown.
1832+
// We purposely do not await it.
1833+
if (this.searchInputActionBar && this.showAiResultsAction && this.searchInputActionBar.hasAction(this.showAiResultsAction)) {
1834+
this.aiSearchPromise = createCancelablePromise(token => {
1835+
return this.doAiSearch(query, token).then((results) => {
1836+
if (results && this.showAiResultsAction) {
1837+
this.showAiResultsAction.enabled = true;
1838+
this.showAiResultsAction.label = SHOW_AI_RESULTS_ENABLED_LABEL;
1839+
this.renderResultCountMessages(true);
1840+
}
1841+
}).catch(e => {
1842+
if (!isCancellationError(e)) {
1843+
this.logService.trace('Error during AI settings search:', e);
1844+
}
1845+
});
18421846
});
1843-
});
1847+
}
18441848

18451849
this.onDidFinishSearch(expandResults, progressRunner);
18461850
});

0 commit comments

Comments
 (0)