Skip to content

Preserve Explorer rename input when the window loses focus - #338126

Merged
Logan Ramos (lramos15) merged 18 commits into
microsoft:mainfrom
r3na7:fix/rename-window-blur
Oct 20, 2026
Merged

Logan Ramos (lramos15) merged 18 commits into
microsoft:mainfrom
r3na7:fix/rename-window-blur

Conversation

@r3na7

@r3na7 renat (r3na7) commented Sep 26, 2026 •

Copy link
Copy Markdown

Fixes #338125

Switching input sources through GNOME Shell's switcher on Wayland can close the Explorer rename input and accept a valid pending filename. The blur handler checks document.hasFocus() first, so losing page focus finishes editing even when the input remains the document's active element.

Check the input's own ownerDocument.activeElement before deciding to finish editing. This preserves the input, pending text and selection when the page loses focus. Moving focus to another element in the document still finishes editing, and the existing context-menu handling is retained.

This intentionally also preserves rename across window switches such as Alt+Tab, provided the input remains its document's active element.

Adds two Electron tests using the real FilesRenderer: preserving rename on page blur, and finishing it when focus moves to another input. A test-only IPC helper focuses a second WebContentsView to produce page blur without changing the original document's active element.

Validation (rechecked after rebasing onto c94d3d7ed24, with Electron 43.7.3):

  • Before rebasing, the preservation test was verified to fail without the fix. Both new tests pass with the fix after rebasing, using the Wayland backend.
  • TypeScript checking, ESLint on the changed files, and git diff --check passed.
  • Manually verified on GNOME Shell 46.0 / Wayland: switching input sources preserves rename with the fix and closes it without the fix. Enter, Escape and dismissing the input context menu before continuing to type also work.

To reproduce: select a file in Explorer, press F2, edit the name without confirming, then switch input sources using the configured shortcut (for example, Super+Space). The input should remain open. The GNOME switcher scenario was verified manually; the automated tests cover page-focus handling.

Run the tests after compiling:

./scripts/test.sh --ozone-platform=wayland --run src/vs/workbench/contrib/files/test/electron-browser/explorerRename.test.ts

Demo

Before the fix — installed VS Code, Wayland:

Screencast.from.2026-09-30.21-44-27.mp4

After the fix — development build with this PR, Wayland:

Screencast.from.2026-09-30.21-46-20.mp4

Copilot AI balanced review requested due to automatic review settings September 26, 2026 17:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@r3na7

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

All reviewed changes are covered by regression tests and no blocking issues were identified.

Review effort: Lite
Findings: None

@r3na7
renat (r3na7) force-pushed the fix/rename-window-blur branch from 04d0907 to 6cdf0cb Compare October 5, 2026 00:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified.

Review effort: Lite
Findings: None

@lramos15

Copy link
Copy Markdown
Member

I just revamped a large portion of the rename input, can you address the merge conflicts please

Keep the upstream Explorer inline-edit refactor and move the page-blur
focus check to the shared InlineEditInputBox.

Validation: existing regression fails without the migrated fix; both
Explorer focus tests and seven InlineEditInputBox tests pass on Wayland
with Electron 43.7.5. ESLint and diff against main checks pass.
TypeScript reports the same 583 diagnostics as unmodified main with
the available local dependencies.
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Benjamin Christopher Simmonds (@benibenj)

Matched files:

  • src/vs/workbench/browser/parts/views/inlineEditInputBox.ts

@r3na7

Copy link
Copy Markdown
Author

Logan Ramos (@lramos15) Sorry for the delay! I've merged the latest main and resolved the conflicts, keeping the new InlineEditInputBox implementation and moving the focus fix there. The Explorer regression tests and existing InlineEditInputBox tests pass.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved review issues remain, and all reviewers assessed it as approval-ready.

0 open findings

🧠 Review effort: Lite

@lramos15 Logan Ramos (lramos15) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, and for moving it into the new InlineEditInputBox after the rework! The input-source switching case looks right, and the Electron focus helper is a nice way to test it.

One regression to address before merging: Chromium doesn't dispatch blur for focus changes made while the window is unfocused. Before this change that didn't matter, because losing window focus always finished editing. Now the blur from the window losing focus hits the return branch, so nothing is waiting any longer. If focus then moves inside VS Code while it's in the background, the inline edit stays open with focus elsewhere and never finishes. For example: an extension calls showTextDocument, the debugger focuses the editor when a breakpoint hits, or code -r file runs. Because this class is shared, that applies to Explorer, terminal tabs, Ports and Timeline. In Explorer the item stays in its editing state until the user clicks back into the box.

I've left two suggestions inline:

  1. In the activeElement branch, wait for the window to regain focus and check again, instead of returning.
  2. A regression test for that scenario, using your focus helper.

Validated locally on macOS:

  • The new test fails on the current head (connected: true, finished: []).
  • With both suggestions applied, all 11 tests in explorerRename.test.ts and inlineEditInputBox.test.ts pass consistently (3 runs), including your two tests.
  • npm run typecheck-client and ESLint on the changed files are clean.

Smaller, non-blocking:

  • Since the change now lives in the shared InlineEditInputBox, these tests might fit better as an electron-browser test next to src/vs/workbench/test/browser/parts/views/inlineEditInputBox.test.ts that constructs InlineEditInputBox directly, rather than going through FilesRenderer with Explorer stubs.
  • It's worth a sentence in the class doc comment saying that the window losing focus (e.g. Alt+Tab or an OS input-source switcher) keeps editing, since that's a deliberate change from the previous behavior.

@r3na7
renat (r3na7) force-pushed the fix/rename-window-blur branch from cfcd228 to 1d0b089 Compare October 19, 2026 14:14
renat (r3na7) and others added 2 commits October 19, 2026 17:15
Co-authored-by: Logan Ramos <lramos15@gmail.com>
…ename.test.ts

Co-authored-by: Logan Ramos <lramos15@gmail.com>
@r3na7

Copy link
Copy Markdown
Author

Logan Ramos (@lramos15) Thanks for the review! I've applied both suggestions and resolved the threads. All 11 tests, type checking, and ESLint passed locally with these changes.

@r3na7

Copy link
Copy Markdown
Author

Logan Ramos (@lramos15) I forgot to address the two non-blocking suggestions in my previous update. Both are now done: the Electron tests construct InlineEditInputBox directly, and the class documentation explains the window-focus behavior. All 11 checks and ESLint pass locally.

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.

Explorer rename input closes when switching input sources on GNOME Wayland

5 participants