Skip to content

Commit 068ee78

Browse files
ScarlettCopilot
andcommitted
Fix dock icons disappearing on discard after size change (#47253)
When dock size is changed in settings while in edit mode and then discarded, the DockControl.DockSize DP was never restored to the pre-edit value. This caused a state mismatch where the view rendered at the wrong size while the ViewModel held the original settings. Fix: RestoreBandOrder() now persists the snapshot settings back to the service (while _isEditing is still true to prevent redundant rebuilds) and returns the restored DockSettings. DiscardEditMode() uses those settings to immediately sync the DockControl's DockSize and related properties. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6f5ea3b commit 068ee78

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Dock/DockViewModel.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,14 +638,18 @@ public void SnapshotBandOrder()
638638
/// Restores the band order and label settings from the snapshot taken when entering edit mode.
639639
/// Call this when discarding edit mode changes.
640640
/// </summary>
641-
public void RestoreBandOrder()
641+
/// <returns>The restored DockSettings, or null if no snapshot exists.</returns>
642+
public DockSettings? RestoreBandOrder()
642643
{
643644
if (_snapshotDockSettings == null || _snapshotBandViewModels == null)
644645
{
645646
Logger.LogWarning("No snapshot to restore from");
646-
return;
647+
return null;
647648
}
648649

650+
// Capture the snapshot before clearing
651+
var restoredSettings = _snapshotDockSettings;
652+
649653
// Restore ShowLabels for all snapshotted bands
650654
foreach (var band in _snapshotBandViewModels.Values)
651655
{
@@ -658,10 +662,17 @@ public void RestoreBandOrder()
658662
// Rebuild UI collections from restored settings using the snapshotted ViewModels
659663
RebuildUICollectionsFromSnapshot();
660664

665+
// Persist restored settings back to the service while _isEditing is still true,
666+
// so that if SettingsChanged fires and calls UpdateSettings(), the _isEditing
667+
// guard prevents redundant SetupBands() (we just rebuilt from snapshot).
668+
SaveSettings();
669+
661670
_snapshotDockSettings = null;
662671
_snapshotBandViewModels = null;
663672
_isEditing = false;
664673
Logger.LogDebug("Restored band order from snapshot");
674+
675+
return restoredSettings;
665676
}
666677

667678
private void RebuildUICollectionsFromSnapshot()

src/modules/cmdpal/Microsoft.CmdPal.UI/Dock/DockControl.xaml.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,12 @@ internal void DiscardEditMode()
261261
IsEditMode = false;
262262

263263
// Restore the original band order from snapshot
264-
ViewModel.RestoreBandOrder();
264+
var restoredSettings = ViewModel.RestoreBandOrder();
265+
if (restoredSettings != null)
266+
{
267+
// Sync DockControl state (DockSize, Side, etc.) to the restored settings
268+
UpdateSettings(restoredSettings);
269+
}
265270
}
266271

267272
private void DoneEditingButton_Click(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)