Skip to content

Fix webview find widget not working after moving editor group to new window#269509

Open
magliocchetti wants to merge 1 commit intomicrosoft:mainfrom
magliocchetti:233044-fix-webview-find-widget-new-window
Open

Fix webview find widget not working after moving editor group to new window#269509
magliocchetti wants to merge 1 commit intomicrosoft:mainfrom
magliocchetti:233044-fix-webview-find-widget-new-window

Conversation

@magliocchetti
Copy link
Copy Markdown
Contributor

Description

Fixes #233044

This PR fixes an issue where webview panels with enableFindWidget enabled would stop working after being moved to a new window using the "View: Move Editor Group into New Window" command. The find widget would appear, but search results would not be highlighted in the webview.

Root Cause

When a webview is moved to a new window, setContextKeyService() is called to update the context key service to the new window's instance. However, the WebviewFindWidget was not updating its internal context keys. Specifically, the _findWidgetFocused context key remained bound to the old window's context key service, causing the find functionality to break.

Changes

webviewFindWidget.ts

  • Store the context key service reference for later updates
  • Add updateContextKeyService() method that:
    • Resets the old _findWidgetFocused context key
    • Updates the stored context key service reference
    • Rebinds _findWidgetFocused to the new context key service

webviewElement.ts

  • Update setContextKeyService() to propagate context key service updates to the find widget

Testing

To verify the fix:

  1. Install the webview-sample extension from the VS Code Extension Samples
  2. Replace src/extension.ts with the code from the issue description
  3. Run the extension and execute "Cat Coding: Start cat coding session"
  4. Press Ctrl-F and search for "text" - verify it highlights correctly
  5. Run "View: Move Editor Group into New Window"
  6. Press Ctrl-F and search for "text" - verify it now highlights correctly (previously would not work)

This is a minimal, focused fix that follows the existing pattern for updating context keys when components move between windows.

Fixes microsoft#233044

When a webview panel with enableFindWidget is moved to a new window
using "Move Editor Group into New Window", the find widget would appear
but fail to highlight search results.

The issue was that the WebviewFindWidget's context keys remained bound
to the original window's context key service. When moved to a new window,
the setContextKeyService method updated the webview's context service but
not the find widget's internal context keys.

This fix:
- Adds updateContextKeyService() method to WebviewFindWidget to rebind
  the _findWidgetFocused context key when the context service changes
- Updates WebviewElement.setContextKeyService() to propagate the context
  service update to the find widget

The find widget now properly updates its context keys when moved between
windows, allowing search functionality to work correctly.

Signed-off-by: Giovanni Magliocchetti <giovimag123@gmail.com>
Copilot AI review requested due to automatic review settings October 2, 2025 10:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Fixes a bug where webview find widgets stopped working after moving editor groups to new windows. The issue occurred because the find widget's context keys remained bound to the old window's context key service.

  • Added updateContextKeyService() method to WebviewFindWidget to rebind context keys
  • Modified WebviewElement.setContextKeyService() to propagate updates to the find widget
  • Changed _findWidgetFocused from readonly to mutable to support rebinding

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/vs/workbench/contrib/webview/browser/webviewFindWidget.ts Adds context key service update functionality and stores reference for later updates
src/vs/workbench/contrib/webview/browser/webviewElement.ts Propagates context key service updates to the find widget

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.

Webview Panel with enableFindWidget does not work after Moving Editor Group into New Window

4 participants