Skip to content

Commit

Permalink
Also fire an event when focus & selection goes to empty (#209145)
Browse files Browse the repository at this point in the history
Fixes #209074
  • Loading branch information
TylerLeonhardt authored Mar 29, 2024
1 parent e483d84 commit b4f1a54
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/vs/platform/quickinput/browser/quickInputTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as dom from 'vs/base/browser/dom';
import { Emitter, Event } from 'vs/base/common/event';
import { IHoverDelegate } from 'vs/base/browser/ui/hover/hoverDelegate';
import { IListVirtualDelegate } from 'vs/base/browser/ui/list/list';
import { IObjectTreeElement, ITreeNode, ITreeRenderer } from 'vs/base/browser/ui/tree/tree';
import { IObjectTreeElement, ITreeEvent, ITreeNode, ITreeRenderer } from 'vs/base/browser/ui/tree/tree';
import { localize } from 'vs/nls';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { WorkbenchObjectTree } from 'vs/platform/list/browser/listService';
Expand Down Expand Up @@ -696,6 +696,8 @@ export class QuickInputTree extends Disposable {
private readonly _onSeparatorButtonTriggered = new Emitter<IQuickPickSeparatorButtonEvent>();
onSeparatorButtonTriggered = this._onSeparatorButtonTriggered.event;

private readonly _onTriggerEmptySelectionOrFocus = new Emitter<ITreeEvent<IQuickPickElement | null>>();

private readonly _container: HTMLElement;
private readonly _tree: WorkbenchObjectTree<IQuickPickElement, void>;
private readonly _separatorRenderer: QuickPickSeparatorElementRenderer;
Expand Down Expand Up @@ -748,7 +750,7 @@ export class QuickInputTree extends Disposable {
?? element.separator?.id
?? element.separator?.label
?? '';
}
},
},
alwaysConsumeMouseWheel: true
}
Expand All @@ -762,15 +764,15 @@ export class QuickInputTree extends Disposable {
@memoize
get onDidChangeFocus() {
return Event.map(
this._tree.onDidChangeFocus,
Event.any(this._tree.onDidChangeFocus, this._onTriggerEmptySelectionOrFocus.event),
e => e.elements.filter((e): e is QuickPickItemElement => e instanceof QuickPickItemElement).map(e => e.item)
);
}

@memoize
get onDidChangeSelection() {
return Event.map(
this._tree.onDidChangeSelection,
Event.any(this._tree.onDidChangeSelection, this._onTriggerEmptySelectionOrFocus.event),
e => ({
items: e.elements.filter((e): e is QuickPickItemElement => e instanceof QuickPickItemElement).map(e => e.item),
event: e.browserEvent
Expand Down Expand Up @@ -1504,7 +1506,15 @@ export class QuickInputTree extends Disposable {
});
}
}
const before = this._tree.getFocus().length;
this._tree.setChildren(null, elements);
// Temporary fix until we figure out why the tree doesn't fire an event when focus & selection
// get changed to empty arrays.
if (before > 0 && elements.length === 0) {
this._onTriggerEmptySelectionOrFocus.fire({
elements: []
});
}
this._tree.layout();

this._onChangedAllVisibleChecked.fire(this.getAllVisibleChecked());
Expand Down

0 comments on commit b4f1a54

Please sign in to comment.