Search code examples
webviewwebview2

How to deselect text in a `ICoreWebView2` control?


Assume that we have 2 ICoreWebView2 controls in a panel, and they are X and Y. When there is any text selected in X, if we then select text in Y, we can observe that the text we selected in X is still selected, even though X has lost keyboard focus, which is now in Y.

How do we "deselect all" in X, when X loses keyboard focus?

By the way, this (deselecting all in X) is the default behavior on WebKit2, but ICoreWebView2 has different behavior. To make our application cross-platform, we need them to have the same behavior so that other codes won't be confused by multiple selected texts. Thanks.


Solution

  • Problem solved! Just call this JavaScript function on X, whenever Y gets the keyboard focus.