Skip to content

Commit

Permalink
Fix search text input issues (#209365)
Browse files Browse the repository at this point in the history
Fixes #209361
  • Loading branch information
andreamah authored Apr 2, 2024
1 parent a86f13b commit e153ed5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class NotebookFindInputFilterButton extends Disposable {
return this._filterButtonContainer;
}

get width() {
width() {
return 2 /*margin left*/ + 2 /*border*/ + 2 /*padding*/ + 16 /* icon width */;
}

Expand All @@ -194,6 +194,14 @@ export class NotebookFindInputFilterButton extends Disposable {
this.container.setAttribute('aria-disabled', String(true));
}

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

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

applyStyles(filterChecked: boolean): void {
const toggleStyles = this._toggleStyles;

Expand Down Expand Up @@ -235,7 +243,7 @@ export class NotebookFindInput extends FindInput {
this._register(registerAndCreateHistoryNavigationContext(contextKeyService, this.inputBox));
this._findFilter = this._register(new NotebookFindInputFilterButton(filters, contextMenuService, instantiationService, options));

this.inputBox.paddingRight = (this.caseSensitive?.width() ?? 0) + (this.wholeWords?.width() ?? 0) + (this.regex?.width() ?? 0) + this._findFilter.width;
this.inputBox.paddingRight = (this.caseSensitive?.width() ?? 0) + (this.wholeWords?.width() ?? 0) + (this.regex?.width() ?? 0) + this._findFilter.width();
this.controls.appendChild(this._findFilter.container);
}

Expand Down
45 changes: 28 additions & 17 deletions src/vs/workbench/contrib/search/browser/searchFindInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class SearchFindInput extends ContextScopedFindInput {
private _findFilter: NotebookFindInputFilterButton;
private _aiButton: AIToggle;
private _filterChecked: boolean = false;
private _visible: boolean = false;
private readonly _onDidChangeAIToggle = this._register(new Emitter<boolean>());
public readonly onDidChangeAIToggle = this._onDidChangeAIToggle.event;

Expand All @@ -36,7 +35,7 @@ export class SearchFindInput extends ContextScopedFindInput {
readonly contextMenuService: IContextMenuService,
readonly instantiationService: IInstantiationService,
readonly filters: NotebookFindFilters,
private _shouldShowAIButton: boolean, // caller responsible for updating this when it changes,
shouldShowAIButton: boolean, // caller responsible for updating this when it changes,
filterStartVisiblitity: boolean
) {
super(container, contextViewProvider, options, contextKeyService);
Expand All @@ -58,12 +57,13 @@ export class SearchFindInput extends ContextScopedFindInput {

this.setAdditionalToggles([this._aiButton]);


this.inputBox.paddingRight = (this.caseSensitive?.width() ?? 0) + (this.wholeWords?.width() ?? 0) + (this.regex?.width() ?? 0) + this._findFilter.width;
this._updatePadding();

this.controls.appendChild(this._findFilter.container);
this._findFilter.container.classList.add('monaco-custom-toggle');
this.filterVisible = filterStartVisiblitity;
// ensure that ai button is visible if it should be
this.sparkleVisible = shouldShowAIButton;

this._register(this._aiButton.onChange(() => {
if (this._aiButton.checked) {
Expand All @@ -78,34 +78,38 @@ export class SearchFindInput extends ContextScopedFindInput {
this._findFilter.enable();
}
}));
}

// ensure that ai button is visible if it should be
this._aiButton.domNode.style.display = _shouldShowAIButton ? '' : 'none';
private _updatePadding() {
this.inputBox.paddingRight =
(this.caseSensitive?.width() ?? 0) +
(this.wholeWords?.width() ?? 0) +
(this.regex?.width() ?? 0) +
(this._findFilter.visible ? this._findFilter.width() : 0) +
(this._aiButton.visible ? this._aiButton.width() : 0);
}

set shouldShowAIButton(visible: boolean) {
if (this._shouldShowAIButton !== visible) {
this._shouldShowAIButton = visible;
this._aiButton.domNode.style.display = visible ? '' : 'none';
}
set sparkleVisible(visible: boolean) {
this._aiButton.visible = visible;
this._updatePadding();
}

set filterVisible(visible: boolean) {
this._findFilter.container.style.display = visible ? '' : 'none';
this._visible = visible;
this.updateStyles();
this._findFilter.visible = visible;
this.updateFilterStyles();
this._updatePadding();
}

override setEnabled(enabled: boolean) {
super.setEnabled(enabled);
if (enabled && (!this._filterChecked || !this._visible)) {
if (enabled && (!this._filterChecked || !this._findFilter.visible)) {
this.regex?.enable();
} else {
this.regex?.disable();
}
}

updateStyles() {
updateFilterStyles() {
// filter is checked if it's in a non-default state
this._filterChecked =
!this.filters.markupInput ||
Expand All @@ -114,7 +118,6 @@ export class SearchFindInput extends ContextScopedFindInput {
!this.filters.codeOutput;

// TODO: find a way to express that searching notebook output and markdown preview don't support regex.

this._findFilter.applyStyles(this._filterChecked);
}

Expand All @@ -135,4 +138,12 @@ 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';
}
}
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export class SearchView extends ViewPane {
private refreshHasAISetting() {
const val = this.shouldShowAIButton();
if (val && this.searchWidget.searchInput) {
this.searchWidget.searchInput.shouldShowAIButton = val;
this.searchWidget.searchInput.sparkleVisible = val;
}
}
private onDidChangeWorkbenchState(): void {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/search/browser/searchWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class SearchWidget extends Widget {
this._register(
this._notebookFilters.onDidChange(() => {
if (this.searchInput) {
this.searchInput.updateStyles();
this.searchInput.updateFilterStyles();
}
}));
this._register(this.editorService.onDidEditorsChange((e) => {
Expand Down

0 comments on commit e153ed5

Please sign in to comment.