Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Problem/Bug]: Detect if a Find session is in progress or has been stopped #5062

Open
pushkin- opened this issue Jan 27, 2025 · 2 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@pushkin-
Copy link

pushkin- commented Jan 27, 2025

What happened?

I detect Ctrl+F/F3 in my app.

When Ctrl+F is pressed, I use the StartAsync API to show the Find popup.

If F3 is pressed, I'll show the Find popup in the same way if one isn't already, but if it's started already, I want to continue searching the same Find session.

I need to know if a Find is in progress or not. Closing the Find popup and then querying the FindInterface still shows an active session (I suppose, because Stop wasn't explicitly called):
Image
(it still shows this after the Find popup is closed; it's possible this is expected actually since the Find text is preservered in a browser too when closing and reopening it; though in WebView2 it's only preserved once and then the text I was searching for gets reset)

I want to know when the FInd popup was closed, so I can know if F3 should open a new Find popup via StartAsync or continue a search via FindNext/FindPrevious. Also, if the Find UI has been closed, I can call Stop() to clear out the text in the Find UI, since in my case, I want to reset everything on close.

So perhaps an event that's triggered when the popup closes would be useful here; alternatively, it might be nice to call one API and have it figure out if it should open a new Find popup or focus and search an existing one.
StartAsync will do a search if a find session is in progress, but it will search in the same direction as was searched last time (according to the docs). If a user presses Shift+F3 or F3, I want to adjust the search direction in response to that which would require explicitly calling FindNext or FindPrevious (which doesn't seem to work as per #5060)

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Prerelease (Edge Canary/Dev/Beta)

Runtime Version

134.0.3101.0 canary

SDK Version

1.0.3079.0 prerelease

Framework

Winforms

Operating System

Windows 11

OS Version

23H2 - 22631.4602

Repro steps

can post an example if you'd like

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

@pushkin- pushkin- added the bug Something isn't working label Jan 27, 2025
@chetanpandey1266 chetanpandey1266 self-assigned this Jan 30, 2025
@chetanpandey1266
Copy link

Can you please show this in a sample app which I can run on my machine.

@pushkin-
Copy link
Author

pushkin- commented Feb 7, 2025

@chetanpandey1266 this issue somewhat intersects with others issues I've opened up. Like testing this runs into other problems I've reported related to Focus and FindNext not working.

Sure I can post an example. I'll add the zip below, but basically my changes to the basic WebView2 WinForms example are: I disable AreBrowserAcceleratorKeysEnabled in WebView2Control_CoreWebView2InitializationCompleted and then add this code:

	private void WebView2Control_KeyDown(object sender, KeyEventArgs e)
	{
		if (e.KeyCode == Keys.F && Control.ModifierKeys.HasFlag(Keys.Control))
		{
			DoFind(null);
		}
		else if (e.KeyCode == Keys.F3)
		{
			DoFind(Control.ModifierKeys.HasFlag(Keys.Shift));
		}
	}

	private void DoFind(bool? searchForward)
	{
		var coreWV2 = webView2Control.CoreWebView2;
		if (searchForward == null)
		{ // we're doing a new search
			var findOptions = coreWV2.Environment.CreateFindOptions();
			findOptions.FindTerm = string.Empty;
			coreWV2.Find.StartAsync(findOptions);
		}
		else
		{
			if (searchForward == true)
			{
				// however, if the Find popup was closed, I'd want to open it back up
				// and FindNext doesn't seem to do that.
				coreWV2.Find.FindNext();
			}
			else
			{
				coreWV2.Find.FindPrevious();
			}
		}
	}

WebView2WindowsFormsBrowser.zip

run with the Canary channel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants