Skip to content

Restore tab selection during drag#1000

Merged
wieslawsoltes merged 3 commits intomasterfrom
fix/issue-861-dock-drop
Jan 22, 2026
Merged

Restore tab selection during drag#1000
wieslawsoltes merged 3 commits intomasterfrom
fix/issue-861-dock-drop

Conversation

@wieslawsoltes
Copy link
Copy Markdown
Owner

PR Summary: Issue 861 - Restore tab selection during drag

Summary

This change fixes an interaction bug where clicking a different tab and immediately starting a drag could switch the selected document/tool before the dock drag began. The selection now stays on the originally active tab when a drag threshold is reached or when the pointer exits the tab strip bounds to begin a dock drag. This prevents accidental tab activation and avoids focus/preview jumps while initiating a drag operation.

Implementation details

Selection capture and restore

  • The tab drag helper (ItemDragHelper) now captures the current selection on pointer press when the owner sits inside a SelectingItemsControl (e.g., TabStrip).
  • When drag initiation happens, selection is restored in two scenarios:
    • Out-of-bounds drag start (pointer leaves the tab strip to start a dock drag).
    • Drag threshold met (dragging far enough to start reordering).
  • Selection is restored by preferred item, then by index if the item is no longer in the collection, and is only done once per drag sequence.
  • All tracking state is cleared on release, capture loss, and detach to avoid stale state.

No API surface changes

  • Behavior is internal to ItemDragHelper and applies to all controls that use it:
    • DocumentTabStripItem
    • ToolTabStripItem
    • ToolPinItemControl
  • No public API or XAML changes are required for consumers.

Usage / behavior notes

User-facing behavior

  • Clicking a tab and immediately dragging it does not switch the active tab unless the drag ends in a reorder/drop.
  • When a drag leaves the bounds (to begin dock drag), selection stays on the original tab.
  • When reordering tabs within the strip, the selection still follows the dropped item as before.

Developer-facing behavior

  • No configuration is needed; the fix is automatic for any control using ItemDragHelper.
  • If you subclass/compose a custom tab strip and use ItemDragHelper, the same behavior applies without additional work.

Tests

New headless tests validate both restoration paths:

  • DocumentTabStripSelectionRestoreTests.DragOutside_RestoresSelection
  • DocumentTabStripSelectionRestoreTests.DragThreshold_RestoresSelection

These tests simulate pointer press/move sequences and verify that selection returns to the original tab when drag starts.

Fixes #861

@wieslawsoltes wieslawsoltes merged commit 0d23efa into master Jan 22, 2026
7 checks passed
@wieslawsoltes wieslawsoltes deleted the fix/issue-861-dock-drop branch January 22, 2026 10:33
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.

Dock target disappears when clicking another dock before mouse release and error control has no logical parent.

1 participant