Skip to content

Respect IsCollapsable in proportional cleanup#998

Merged
wieslawsoltes merged 2 commits intomasterfrom
fix/issue-933-collapsable
Jan 22, 2026
Merged

Respect IsCollapsable in proportional cleanup#998
wieslawsoltes merged 2 commits intomasterfrom
fix/issue-933-collapsable

Conversation

@wieslawsoltes
Copy link
Owner

PR Summary: Issue 933 - Preserve Non-Collapsable ProportionalDock

Summary

This change fixes issue #933 where ProportionalDock.IsCollapsable = false prevented empty-dock collapsing but did not prevent single-child simplification. The proportional cleanup routine now respects IsCollapsable, so non-collapsable proportional docks remain in the layout tree even when left with a single child.

Problem

FactoryBase.CollapseDock correctly checks IsCollapsable for empty-dock removal. However, when a child dock is collapsed and the parent proportional dock ends up with a single child, CleanupProportionalDockTree used to simplify the tree unconditionally. This could remove a structural ProportionalDock even when IsCollapsable = false.

Fix Overview

  • CleanupProportionalDockTree now returns early when dock.IsCollapsable is false.
  • This keeps non-collapsable proportional docks in the tree during simplification passes.
  • Existing behavior for collapsable docks is unchanged.

Implementation Details

Code Change

The guard lives in FactoryBase.CleanupProportionalDockTree:

private void CleanupProportionalDockTree(IProportionalDock dock)
{
    if (dock.VisibleDockables == null || dock.Owner is not IDock owner || dock.Owner is IRootDock)
        return;
    if (!dock.IsCollapsable)
        return;

    // existing single-child simplification logic...
}

Regression Test

A new headless test covers the scenario from issue #933 by:

  1. Creating a proportional dock (mainArea) with IsCollapsable = false that contains a document, a splitter, and a collapsable bottom pane.
  2. Collapsing the empty bottom pane.
  3. Verifying that mainArea remains in the tree with the document as its only child.

Test location:

  • tests/Dock.Avalonia.HeadlessTests/FactorySplitTests.cs

Behavior Changes

  • Before: A ProportionalDock with IsCollapsable = false could still be simplified away when it had a single child.
  • After: Non-collapsable proportional docks are preserved during cleanup, even when left with a single child.

Usage Guidance

If you want a proportional dock to stay as a persistent layout container, set IsCollapsable = false on it:

var mainArea = new ProportionalDock
{
    Id = "MainArea",
    IsCollapsable = false,
    VisibleDockables = factory.CreateList<IDockable>()
};

This ensures that both empty-dock collapse and single-child simplification will not remove the dock. For docks that should be simplified when reduced to a single child, keep the default (IsCollapsable = true).

Tests

  • Added: CollapseDock_DoesNotSimplify_NonCollapsable_ProportionalDock
  • Suite: Dock.Avalonia.HeadlessTests

Fixes #933

@wieslawsoltes wieslawsoltes merged commit 401fea8 into master Jan 22, 2026
8 checks passed
@wieslawsoltes wieslawsoltes deleted the fix/issue-933-collapsable branch January 22, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IsCollapsable=false on ProportionalDock Does Not Prevent Its Removal During Layout Simplification

1 participant