From b4c8a6708c682827f5150f322549d62bed4e4399 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Fri, 4 Dec 2026 17:31:55 +0800 Subject: [PATCH] fix(plugins): give the keyboard to a plugin dialog's or tool window's page (#8003) A plugin dialog focused its Close button while its page loaded, and a plugin web tool window left the focus on its body when activated, so typing went nowhere until the user clicked into the page. WebKit doesn't let a sandboxed frame focus a field before the user acts on it, so the page's autofocus or focus() could not help. The dialog and the tool window now focus the plugin frame, and the frame bridge sends a key typed while nothing in the page has the focus to the page's autofocus field. Shortcuts, Tab and Escape keep their meaning. Fixes #7973 --- plugins/README.md | 3 ++ .../plugins/__tests__/dialogs.test.tsx | 43 ++++++++++++++++--- .../plugins/__tests__/webViews.test.tsx | 4 ++ src/features/plugins/views/WebView.tsx | 12 ++++++ src/features/plugins/views/frame-bridge.js | 15 +++++++ 5 files changed, 71 insertions(+), 6 deletions(-) diff --git a/plugins/README.md b/plugins/README.md index 25992ee2a7..e266f43f96 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -2748,6 +2748,9 @@ fn handle(view: &str, event: ViewEvent) { The page talks to the plugin's code as any web view does (`openidea.postMessage` / `onMessage`, `views::post_message("preview", …)`), and sees nothing else of the IDE, so a dialog needs no capability. Only a dialog's page has `openidea.dialog`. +The dialog gives its page the keyboard when it opens, as a tool window does when +activated. The engine doesn't let a sandboxed page focus a field before the user +types or clicks, so mark the field with `autofocus`: the first key typed goes to it. For something that stays open beside the editor without taking the keyboard, use an [overlay](#overlays) or a tool window. diff --git a/src/features/plugins/__tests__/dialogs.test.tsx b/src/features/plugins/__tests__/dialogs.test.tsx index d827a97951..abb48b2e07 100644 --- a/src/features/plugins/__tests__/dialogs.test.tsx +++ b/src/features/plugins/__tests__/dialogs.test.tsx @@ -13,22 +13,24 @@ afterEach(() => { localStorage.clear(); }); -/** Runs the bridge in a fake frame window at `search`; what it posts up and its keydown handler. */ -function bridgeAt(search: string) { +/** Runs the bridge in a fake frame window at `search`; what it posts up and its keydown handlers. */ +function bridgeAt(search: string, doc: Record = {}) { const script = /