Skip to content

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 9, 2025

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:

Issue Screenshot

Root Cause

The TreeRenderer.renderElement method in abstractTree.ts always applies a base indentation of 8px (TreeRenderer.DefaultIndent) regardless of whether nodes are collapsible or need hierarchy visualization:

templateData.indentSize = TreeRenderer.DefaultIndent + (node.depth - 1) * this.indent;

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:

// 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;
templateData.indentSize = baseIndent + (node.depth - 1) * this.indent;

This change:

  • ✅ Eliminates excessive spacing for single-level trees with checkboxes
  • ✅ Preserves normal indentation for hierarchical trees
  • ✅ Maintains indentation for collapsible first-level nodes
  • ✅ No impact on deeper hierarchy levels

Testing

Created comprehensive test cases validating that:

  • First-level non-collapsible nodes now have 0px base indentation (fixes the issue)
  • First-level collapsible nodes still have 8px indentation (preserved functionality)
  • Multi-level trees remain unaffected (no regression)

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
    • Triggering command: 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.

Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] When there is only one level of nodes and all of them display checkboxes, CustomTreeView has indentation issues Fix CustomTreeView indentation for single-level nodes with checkboxes Jul 9, 2025
@Copilot Copilot AI requested a review from alexr00 July 9, 2025 10:04
Copilot finished work on behalf of alexr00 July 9, 2025 10:04
@@ -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;
Copy link
Member

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.

Copy link
Contributor Author

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:

  1. Tracks whether any first-level nodes are collapsible via hasCollapsibleFirstLevelNodes property
  2. Uses the model to check all first-level nodes (via this.model.getNode().children) to ensure consistency
  3. Only applies 0 indentation when ALL first-level nodes are non-collapsible
  4. 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>
Copy link
Contributor Author

Copilot AI commented Jul 9, 2025

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 addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI requested a review from alexr00 July 9, 2025 10:33
Copilot finished work on behalf of alexr00 July 9, 2025 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When there is only one level of nodes and all of them display checkboxes, CustomTreeView has indentation issues
2 participants