Skip to content
Open
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
46 changes: 3 additions & 43 deletions emain/emain-ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { PNG } from "pngjs";
import { Readable } from "stream";
import { RpcApi } from "../frontend/app/store/wshclientapi";
import { getWebServerEndpoint } from "../frontend/util/endpoints";
import * as keyutil from "../frontend/util/keyutil";
import { fireAndForget, parseDataUrl } from "../frontend/util/util";
import {
incrementTermCommandsDurable,
Expand All @@ -22,16 +21,13 @@ import {
import { createBuilderWindow, getAllBuilderWindows, getBuilderWindowByWebContentsId } from "./emain-builder";
import { callWithOriginalXdgCurrentDesktopAsync, unamePlatform } from "./emain-platform";
import { getWaveTabViewByWebContentsId } from "./emain-tabview";
import { handleCtrlShiftState } from "./emain-util";
import { setWebviewKeys } from "./emain-util";
import { getWaveVersion } from "./emain-wavesrv";
import { createNewWaveWindow, getWaveWindowByWebContentsId } from "./emain-window";
import { ElectronWshClient } from "./emain-wsh";

const electronApp = electron.app;

let webviewFocusId: number = null;
let webviewKeys: string[] = [];

export function openBuilderWindow(appId?: string) {
const normalizedAppId = appId || "";
const existingBuilderWindows = getAllBuilderWindows();
Expand Down Expand Up @@ -280,48 +276,12 @@ export function initIpcHandlers() {
event.returnValue = event.sender.getZoomFactor();
});

const hasBeforeInputRegisteredMap = new Map<number, boolean>();

electron.ipcMain.on("webview-focus", (event: Electron.IpcMainEvent, focusedId: number) => {
webviewFocusId = focusedId;
electron.ipcMain.on("webview-focus", (_event: Electron.IpcMainEvent, focusedId: number) => {
console.log("webview-focus", focusedId);
if (focusedId == null) {
return;
}
const parentWc = event.sender;
const webviewWc = electron.webContents.fromId(focusedId);
if (webviewWc == null) {
webviewFocusId = null;
return;
}
if (!hasBeforeInputRegisteredMap.get(focusedId)) {
hasBeforeInputRegisteredMap.set(focusedId, true);
webviewWc.on("before-input-event", (e, input) => {
let waveEvent = keyutil.adaptFromElectronKeyEvent(input);
handleCtrlShiftState(parentWc, waveEvent);
if (webviewFocusId != focusedId) {
return;
}
if (input.type != "keyDown") {
return;
}
for (let keyDesc of webviewKeys) {
if (keyutil.checkKeyPressed(waveEvent, keyDesc)) {
e.preventDefault();
parentWc.send("reinject-key", waveEvent);
console.log("webview reinject-key", keyDesc);
return;
}
}
});
webviewWc.on("destroyed", () => {
hasBeforeInputRegisteredMap.delete(focusedId);
});
}
});

electron.ipcMain.on("register-global-webview-keys", (event, keys: string[]) => {
webviewKeys = keys ?? [];
setWebviewKeys(keys);
});

electron.ipcMain.on("set-keyboard-chord-mode", (event) => {
Expand Down
15 changes: 15 additions & 0 deletions emain/emain-tabview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { setWasActive } from "./emain-activity";
import { getElectronAppBasePath, isDevVite, unamePlatform } from "./emain-platform";
import {
decreaseZoomLevel,
getWebviewKeys,
handleCtrlShiftFocus,
handleCtrlShiftState,
increaseZoomLevel,
Expand Down Expand Up @@ -322,6 +323,20 @@ export async function getOrCreateWebViewForTab(waveWindowId: string, tabId: stri
tabView.webContents.send("webview-new-window", wc.id, details);
return { action: "deny" };
});
wc.on("before-input-event", (e, input) => {
if (input.type != "keyDown") {
return;
}
const waveEvent = adaptFromElectronKeyEvent(input);
handleCtrlShiftState(tabView.webContents, waveEvent);
for (const keyDesc of getWebviewKeys()) {
if (checkKeyPressed(waveEvent, keyDesc)) {
e.preventDefault();
tabView.webContents.send("reinject-key", waveEvent);
return;
}
}
});
Comment on lines +326 to +339
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.

⚠️ Potential issue | 🟠 Major

Mirror the tab-level chord/modifier handling in the webview path.

This branch returns before handleCtrlShiftState(), so webview keyUp events never clear the ctrl/shift state. It also skips the tabView.keyboardChordMode reinjection path from Lines 346-350, which means a chord started from a reinjected webview shortcut still sends the second key into the webview instead of back to the app.

🛠️ Proposed fix
         wc.on("before-input-event", (e, input) => {
-            if (input.type != "keyDown") {
-                return;
-            }
             const waveEvent = adaptFromElectronKeyEvent(input);
             handleCtrlShiftState(tabView.webContents, waveEvent);
+            if (input.type == "keyDown" && tabView.keyboardChordMode) {
+                e.preventDefault();
+                tabView.setKeyboardChordMode(false);
+                tabView.webContents.send("reinject-key", waveEvent);
+                return;
+            }
+            if (input.type != "keyDown") {
+                return;
+            }
             for (const keyDesc of getWebviewKeys()) {
                 if (checkKeyPressed(waveEvent, keyDesc)) {
                     e.preventDefault();
                     tabView.webContents.send("reinject-key", waveEvent);
                     return;
📝 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
wc.on("before-input-event", (e, input) => {
if (input.type != "keyDown") {
return;
}
const waveEvent = adaptFromElectronKeyEvent(input);
handleCtrlShiftState(tabView.webContents, waveEvent);
for (const keyDesc of getWebviewKeys()) {
if (checkKeyPressed(waveEvent, keyDesc)) {
e.preventDefault();
tabView.webContents.send("reinject-key", waveEvent);
return;
}
}
});
wc.on("before-input-event", (e, input) => {
const waveEvent = adaptFromElectronKeyEvent(input);
handleCtrlShiftState(tabView.webContents, waveEvent);
if (input.type == "keyDown" && tabView.keyboardChordMode) {
e.preventDefault();
tabView.setKeyboardChordMode(false);
tabView.webContents.send("reinject-key", waveEvent);
return;
}
if (input.type != "keyDown") {
return;
}
for (const keyDesc of getWebviewKeys()) {
if (checkKeyPressed(waveEvent, keyDesc)) {
e.preventDefault();
tabView.webContents.send("reinject-key", waveEvent);
return;
}
}
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@emain/emain-tabview.ts` around lines 326 - 339, The webview before-input
handler returns early and thus skips clearing modifier state and the tab-level
chord reinjection logic; update the wc.on("before-input-event") handler so it
always calls handleCtrlShiftState(adaptFromElectronKeyEvent(...)) for both
keyDown and other input types, and when a webview key matches (checkKeyPressed
from getWebviewKeys()) preventDefault then route the reinjection through the
same tabView keyboard chord path: if tabView.keyboardChordMode is active, send
the reinjection back to the host (same path used for tab-level reinjection)
instead of tabView.webContents.send("reinject-key") to the webview, ensuring
keyUp events clear ctrl/shift and chord state is honored consistently.

});
tabView.webContents.on("before-input-event", (e, input) => {
const waveEvent = adaptFromElectronKeyEvent(input);
Expand Down
10 changes: 10 additions & 0 deletions emain/emain-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ export const WaveAppPathVarName = "WAVETERM_APP_PATH";
export const WaveAppResourcesPathVarName = "WAVETERM_RESOURCES_PATH";
export const WaveAppElectronExecPath = "WAVETERM_ELECTRONEXECPATH";

let webviewKeys: string[] = [];

export function getWebviewKeys(): string[] {
return webviewKeys;
}

export function setWebviewKeys(keys: string[]) {
webviewKeys = keys ?? [];
}

const MinZoomLevel = 0.4;
const MaxZoomLevel = 2.6;
const ZoomDelta = 0.2;
Expand Down