Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions v2/internal/frontend/desktop/windows/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,14 @@ func (f *Frontend) navigationCompleted(sender *edge.ICoreWebView2, args *edge.IC
win32.ShowWindow(f.mainWindow.Handle())
}

// Ensure initial keyboard focus goes into the WebView so typing works without a click.
if !f.frontendOptions.StartHidden && f.frontendOptions.WindowStartState != options.Minimised {
if ctrl := f.chromium.GetController(); ctrl != nil {
_ = ctrl.MoveFocus(edge.COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC)
// _ = ctrl.MoveFocus(0)
}
}

Comment on lines +954 to +961

@coderabbitai coderabbitai Bot Aug 12, 2025

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.

🛠️ Refactor suggestion

Add fallback and minimal error handling for MoveFocus to increase compatibility.

Some WebView2 versions/bindings may not support the PROGRAMMATIC constant or may return an error. Fall back to 0 (PROGRAMMATIC in the enum) and finally to Chromium.Focus() so initial typing reliably works.

-        if ctrl := f.chromium.GetController(); ctrl != nil {
-            _ = ctrl.MoveFocus(edge.COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC)
-            // _ = ctrl.MoveFocus(0)
-        }
+        if ctrl := f.chromium.GetController(); ctrl != nil {
+            if err := ctrl.MoveFocus(edge.COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC); err != nil {
+                _ = ctrl.MoveFocus(0) // fallback: enum 0 is PROGRAMMATIC
+                f.chromium.Focus()    // last-resort fallback
+            }
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Ensure initial keyboard focus goes into the WebView so typing works without a click.
if !f.frontendOptions.StartHidden && f.frontendOptions.WindowStartState != options.Minimised {
if ctrl := f.chromium.GetController(); ctrl != nil {
_ = ctrl.MoveFocus(edge.COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC)
// _ = ctrl.MoveFocus(0)
}
}
// Ensure initial keyboard focus goes into the WebView so typing works without a click.
if !f.frontendOptions.StartHidden && f.frontendOptions.WindowStartState != options.Minimised {
if ctrl := f.chromium.GetController(); ctrl != nil {
if err := ctrl.MoveFocus(edge.COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC); err != nil {
_ = ctrl.MoveFocus(0) // fallback: enum 0 is PROGRAMMATIC
f.chromium.Focus() // last-resort fallback
}
}
}
🤖 Prompt for AI Agents
In v2/internal/frontend/desktop/windows/frontend.go around lines 945 to 952,
replace the single MoveFocus call with a small fallback sequence: attempt
ctrl.MoveFocus(edge.COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC) and if it
returns an error (or is unsupported) retry with ctrl.MoveFocus(0); if that also
errors, call f.chromium.Focus() as a last resort; capture any returned errors
and log a minimal debug/warn message (or ignore if logger not available) but do
not panic — this increases compatibility across WebView2 versions and bindings.

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.

@creamy-corn - what do you make of the committable suggestion?

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.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

f.mainWindow.hasBeenShown = true

}
Expand Down
8 changes: 8 additions & 0 deletions v2/internal/frontend/desktop/windows/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
//}
}

if w.isActive && w.chromium != nil {
if ctrl := w.chromium.GetController(); ctrl != nil {
// Push keyboard focus into WebView2 when activated
_ = ctrl.MoveFocus(edge.COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC)
// _ = ctrl.MoveFocus(0) // fallback if your bindings lack the constant
}
}

Comment thread
creamy-corn marked this conversation as resolved.
case 0x02E0: //w32.WM_DPICHANGED
newWindowSize := (*w32.RECT)(unsafe.Pointer(lparam))
w32.SetWindowPos(w.Handle(),
Expand Down