Skip to content

Preserve requested file selection when converting or reusing tabs - #144

Draft
aiolosking wants to merge 1 commit into
w4po:masterfrom
aiolosking:codex/fix-reveal-selection
Draft

aiolosking wants to merge 1 commit into
w4po:masterfrom
aiolosking:codex/fix-reveal-selection

Conversation

@aiolosking

Copy link
Copy Markdown

Opening a file location can reach the correct folder but lose the requested file selection when a new Explorer window is converted to a tab. Reusing an existing tab also returns without applying the incoming selection. This draft shares a locally tested fix and its latency tradeoff for maintainer review.

Reproduction

Tested with v2.5.0 x64 .NET Framework 4.8.1 on Windows 11 Pro 25H2, build 26200.9457. Window Hook and Reuse Tabs enabled; Keyboard Hook and Mouse Hook disabled; known file extensions hidden.

  1. Create a test directory containing sample.txt, sample.md, and a subdirectory. Keep an Explorer window open elsewhere.
  2. Run explorer.exe /select,"C:\path\to\test\sample.txt" (substitute your test directory).
  3. The folder opens as a tab, but the requested file can be unselected.
  4. Repeat with sample.md while the tab already exists. The incoming selection is not restored.
  5. Stop ExplorerTabUtility and repeat the native /select call: selection worked in the local control test.

Related report: #128. That report also describes choosing the wrong tab; this draft does not claim to fix every focus/navigation symptom in that issue.

Changes

  • Keep the source window alive while polling for its initial selection, for at most 800 ms.
  • Store full item paths instead of display names, which may omit extensions.
  • Apply incoming selection when reusing a tab, not only when creating one.
  • Restore selection after navigation completion, with bounded retries and a location check to avoid applying the request after navigation to a different folder.
  • Clear the previous selection on the first item, focus it, and bring it into view; retain multi-selection for subsequent items.

Validation performed locally

  • net481 Release build: zero warnings and zero errors. Local build generated COM interop references from the installed Windows type libraries because full-framework MSBuild was unavailable. Those local build changes, binaries, and SDK files are not included here.
  • Real Explorer /select tests: new tab, reused tab with a different requested file, hidden extensions with identical basenames, Chinese characters/spaces in paths, and subfolder selection.
  • Real SHOpenFolderAndSelectItems tests through a small native-API harness: new-tab file selection and multiple selected files in an existing tab.
  • Read back the actual selected paths through Shell COM, checked that the target had only one tab in the same window, and inspected the selection in the UI. Ordinary folder opening still merged into tabs.
  • Repeated selection verification after restarting the patched utility on the following day.

Why this is a draft

  • The bounded capture wait also adds approximately 800 ms to ordinary folder opens that have no selection. An event-driven or request-aware approach may be preferable; the timeout is a tested workaround, not a claimed optimal design.
  • There is overlap with Fix tab navigation event cleanup and avoid synchronous callback reentry #142's navigation-event lifecycle work. This patch was tested against the v2.5.0 implementation, which still matches the current master file. It should be reconciled with that PR, rather than claiming to solve its subscription/reentrancy concerns.
  • The general COM threading model is unchanged. Slow/network folders, virtual folders, legacy persisted selection history, and rapid overlapping navigation still need broader testing. The net9.0-windows target was not built locally.
  • No claim of compatibility with every third-party application's reveal implementation. Screenshots and raw local logs are deliberately omitted because they contain unrelated personal folder names.

Prepared with AI assistance; the validation above was performed against actual local Explorer windows. Happy to split the identity/reuse fixes from the timing workaround if that is preferable.

lazyalex616 added a commit to lazyalex616/ExplorerTabPlus that referenced this pull request Oct 23, 2026
…lection when converting or reusing tabs

Conflicts with w4po#137/w4po#142 in ExplorerWatcher: kept w4po#137's awaited conversion result (window is restored if conversion fails) while feeding it w4po#144's CaptureInitialSelectionAsync selection; kept w4po#137's IsFileExplorerWindow guard and bool return on tab reuse and added w4po#144's RestoreSelectionAsync there; replaced w4po#142's one-shot SelectItems after navigation with w4po#144's retrying RestoreSelectionAsync, still invoked after the NavigationCompletion wait (outside the COM callback).
notmicaelfilipe added a commit to notmicaelfilipe/ExplorerTabUtility that referenced this pull request Nov 12, 2026
…lers and file selection

From open upstream PRs (w4po/ExplorerTabUtility w4po#137, w4po#142, w4po#144), trimmed down:

- New windows could stay invisible or vanish (upstream w4po#133/w4po#121): hiding and
  tab conversion trusted _windowEntryDict.Count, which stale COM entries
  inflate, so a new window got hidden and converted into itself, then quit.
  Decide from real Explorer windows instead, only quit the window after a tab
  was actually created, skip dead tabs when reusing, and unhide any window
  that registration never handled within 10s.
- NavigateComplete2 handler leaked on the 5s timeout (a later navigation
  re-applied an old selection) and selection ran inside Explorer's COM event
  callback. Shared NavigateAndWait helper: handler only signals, always
  unsubscribes, selection runs after the callback returns.
- Selection used display names, which drop hidden extensions, so ParseName
  missed "file.txt". Store full paths; names saved by older versions still work.

Bump version to 2.6.4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant