Mac - html2.webview losing selection on lost focus

I’m building a simple html rich text editor that formats selected text with bold, italic, etc. on the click of a button. The buttons are on a Toolbar and both the toolbar and webview have the same wx.panel as parent.

On Windows and Linux this works as expected: the user selects a range of text, clicks a button and the action is taken on the selected text (via JavaScript), plus the selection remains. However, on Mac 10.15 the selection is lost as soon as the button is clicked when the webview looses focus.

I have looked for a way to maybe veto the focus change from the webview but found nothing that works. I have tried to intercept the change with onblur in JavaScript, but the selection appears to be gone before JS is run.

Is there a way to deal with this? A workaround? Is this the nature of the Mac Webkit?

(using Python 3.10, wxPython 4.2)

Well, after some more trial and error I found the issue is with AUIToolbar. For some reason on Mac its click events or focus do not work as expected. When I changed the control to the stock wx.ToolBar the selection stays as it should in webview on an item click.

Thanks to all who looked.