Skip to content

Commit

Permalink
Extra action buttons not disabled on AI Search (#209999)
Browse files Browse the repository at this point in the history
Fixes #209696
  • Loading branch information
andreamah authored Apr 10, 2024
1 parent 46b04fe commit 67f1ea8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
8 changes: 8 additions & 0 deletions src/vs/base/browser/ui/toggle/toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ export class Toggle extends Widget {
this._hover.update(newTitle);
this.domNode.setAttribute('aria-label', newTitle);
}

set visible(visible: boolean) {
this.domNode.style.display = visible ? '' : 'none';
}

get visible() {
return this.domNode.style.display !== 'none';
}
}

export class Checkbox extends Widget {
Expand Down
40 changes: 21 additions & 19 deletions src/vs/workbench/contrib/search/browser/searchFindInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class SearchFindInput extends ContextScopedFindInput {
private _filterChecked: boolean = false;
private readonly _onDidChangeAIToggle = this._register(new Emitter<boolean>());
public readonly onDidChangeAIToggle = this._onDidChangeAIToggle.event;
private shouldNotebookFilterBeVisible: boolean = false; // followed, but overriden by the whether aiToggle is visible

constructor(
container: HTMLElement | null,
Expand Down Expand Up @@ -66,25 +67,30 @@ export class SearchFindInput extends ContextScopedFindInput {
this.sparkleVisible = shouldShowAIButton;

this._register(this._aiButton.onChange(() => {
if (this.regex) {
this.regex.visible = !this._aiButton.checked;
}
if (this.wholeWords) {
this.wholeWords.visible = !this._aiButton.checked;
}
if (this.caseSensitive) {
this.caseSensitive.visible = !this._aiButton.checked;
}
if (this._aiButton.checked) {
this.regex?.disable();
this.wholeWords?.disable();
this.caseSensitive?.disable();
this._findFilter.disable();
this._findFilter.visible = false;
} else {
this.regex?.enable();
this.wholeWords?.enable();
this.caseSensitive?.enable();
this._findFilter.enable();
this.filterVisible = this.shouldNotebookFilterBeVisible;
}
this._updatePadding();

}));
}

private _updatePadding() {
this.inputBox.paddingRight =
(this.caseSensitive?.width() ?? 0) +
(this.wholeWords?.width() ?? 0) +
(this.regex?.width() ?? 0) +
(this.caseSensitive?.visible ? this.caseSensitive.width() : 0) +
(this.wholeWords?.visible ? this.wholeWords.width() : 0) +
(this.regex?.visible ? this.regex.width() : 0) +
(this._findFilter.visible ? this._findFilter.width() : 0) +
(this._aiButton.visible ? this._aiButton.width() : 0);
}
Expand All @@ -95,6 +101,10 @@ export class SearchFindInput extends ContextScopedFindInput {
}

set filterVisible(visible: boolean) {
this.shouldNotebookFilterBeVisible = visible;
if (this._aiButton.visible && this._aiButton.checked) {
return;
}
this._findFilter.visible = visible;
this.updateFilterStyles();
this._updatePadding();
Expand Down Expand Up @@ -138,12 +148,4 @@ class AIToggle extends Toggle {
inputActiveOptionBackground: opts.inputActiveOptionBackground
});
}

set visible(visible: boolean) {
this.domNode.style.display = visible ? '' : 'none';
}

get visible() {
return this.domNode.style.display !== 'none';
}
}

0 comments on commit 67f1ea8

Please sign in to comment.