Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also fire an event when focus & selection goes to empty #209145

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading