Skip to content

Expose the focused element and change event in the TreeView API#184268

Merged
alexr00 merged 10 commits into
microsoft:mainfrom
EhabY:tree-view-focus
Jul 14, 2023
Merged

Expose the focused element and change event in the TreeView API#184268
alexr00 merged 10 commits into
microsoft:mainfrom
EhabY:tree-view-focus

Conversation

@EhabY

@EhabY EhabY commented Jun 4, 2023

Copy link
Copy Markdown
Contributor

PR for #170248

This just exposes the focused element through TreeView.focus. On thing that might be confusing is that the TreeView.focus might seem like a boolean that returns true if the view is focused and not the element that is focused. Does TreeView.focusedItem or TreeView.focusedElement make more sense?

@alexr00 alexr00 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I've left some initial comments. We will still need to go through the API review process, but I think exposing a way to get the active tree item is a useful change.

Comment thread src/vscode-dts/vscode.d.ts Outdated
Comment thread src/vscode-dts/vscode.d.ts Outdated
@Giangpro89 Giangpro89 linked an issue Jun 6, 2023 that may be closed by this pull request
@EhabY EhabY requested a review from alexr00 June 6, 2023 11:29

@alexr00 alexr00 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good! I will bring it to our API discussion next week and then merge it assuming that there are no concerns.

@alexr00 alexr00 added this to the June 2023 milestone Jun 8, 2023
@EhabY EhabY requested a review from alexr00 June 16, 2023 12:50

@alexr00 alexr00 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EhabY thank you for the ping. One output from API discussion that needs to be addressed is making sure that the selection is already updated with the active event fires and the active item is already updated with the selection event fires. For example, if you create a tree view and do the following:

		view.onDidChangeActiveItem(e => {
			console.log('selection');
			console.log(view.selection);
			console.log('active');
			console.log(view.activeItem);
	});
		view.onDidChangeSelection(e => {
			console.log('selection');
			console.log(view.selection);
			console.log('active');
			console.log(view.activeItem);
	});

The console logs from the two event listners should print the same thing each time they both fire. To that end $setSelection and $setFocus should be merged into one $setSelectionAndFocus so that both values are set in the same RPC call.

https://github.com/ehaby/vscodetreeviewfocus/blob/b72b9c0ea0a984ae11b3bcd81b9e01dddcc0ab6f/src/vs/workbench/api/common/extHostTreeViews.ts#L235-L249

Comment thread src/vs/workbench/api/browser/mainThreadTreeViews.ts Outdated
alexr00
alexr00 previously approved these changes Jun 19, 2023

@alexr00 alexr00 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! We do not need to wait to address #185563 to merge as this is still proposed API. I will follow up on #185563.

this._register(this.tree.onDidChangeSelection(e => this._onDidChangeSelection.fire(e.elements)));

this._register(this.tree.onDidChangeSelection(e => {
if (e.elements !== this.lastSelection) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems abstractTree.ts already filters along with extHostTreeView.ts

Is this really needed? Especially that those arrays are compared by reference

Comment thread src/vs/workbench/api/common/extHost.protocol.ts Outdated
@EhabY EhabY requested a review from alexr00 June 21, 2023 13:53
@alexr00 alexr00 modified the milestones: June 2023, July 2023 Jun 22, 2023
@EhabY

EhabY commented Jul 10, 2023

Copy link
Copy Markdown
Contributor Author

@alexr00 Please take another look so this can be merged 🙏

@alexr00 alexr00 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I've resolved the conflicts!

@alexr00 alexr00 enabled auto-merge (squash) July 14, 2023 08:35
@alexr00 alexr00 merged commit 6a152ca into microsoft:main Jul 14, 2023
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

https://wikitech.wikimedia.org/wiki/Help:Toolforge/Jobs_framework

4 participants