-
Notifications
You must be signed in to change notification settings - Fork 33.6k
Fix CustomTreeView indentation for single-level nodes with checkboxes #254833
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
@@ -371,7 +371,9 @@ export class TreeRenderer<T, TFilterData, TRef, TTemplateData> implements IListR | |||
this.indent = indent; | |||
|
|||
for (const [node, templateData] of this.renderedNodes) { | |||
templateData.indentSize = TreeRenderer.DefaultIndent + (node.depth - 1) * this.indent; | |||
// For first-level nodes that are not collapsible, use minimal indentation to avoid excessive spacing | |||
const baseIndent = (node.depth === 1 && !node.collapsible) ? 0 : TreeRenderer.DefaultIndent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot, I think we need to check that all the sibling nodes are also not collapsible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the implementation to check that all sibling first-level nodes are non-collapsible before applying the minimal indentation. The new approach:
- Tracks whether any first-level nodes are collapsible via
hasCollapsibleFirstLevelNodes
property - Uses the model to check all first-level nodes (via
this.model.getNode().children
) to ensure consistency - Only applies 0 indentation when ALL first-level nodes are non-collapsible
- Automatically recalculates state when tree structure changes or collapse states change
This ensures visual consistency when there's a mix of collapsible and non-collapsible first-level nodes. Commit 8b425c1 contains the updated implementation.
…nimal indentation Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Problem
When a CustomTreeView contains only first-level nodes with checkboxes (no hierarchy), there's excessive left indentation that wastes horizontal space and creates visual imbalance. The red box in the issue image highlights this unnecessary spacing:
Root Cause
The
TreeRenderer.renderElement
method inabstractTree.ts
always applies a base indentation of 8px (TreeRenderer.DefaultIndent
) regardless of whether nodes are collapsible or need hierarchy visualization:For single-level trees with checkboxes, this creates 8px of unnecessary left padding since there are no expand/collapse twisties or hierarchical structure to visualize.
Solution
Modified the indentation calculation to use minimal indentation for first-level non-collapsible nodes:
This change:
Testing
Created comprehensive test cases validating that:
The fix specifically targets the problematic case (single-level trees with checkboxes) while maintaining backward compatibility for all other tree view scenarios.
Fixes #252934.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
electronjs.org
node-gyp
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.