Skip to content

Commit bb9ac3b

Browse files
Keep inactive webviews from stealing shortcuts
1 parent bfd185e commit bb9ac3b

5 files changed

Lines changed: 62 additions & 8 deletions

File tree

src-tauri/src/commands/ui/window.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,9 @@ pub async fn set_webview_visible(
791791
webview
792792
.hide()
793793
.map_err(|e| format!("Failed to hide webview: {e}"))?;
794+
if let Some(main_webview) = app.get_webview_window("main") {
795+
let _ = main_webview.set_focus();
796+
}
794797
}
795798
} else {
796799
return Err(format!("Webview not found: {webview_label}"));

src/features/panes/components/pane-container.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,12 +1041,8 @@ export function PaneContainer({ pane }: PaneContainerProps) {
10411041
isVisible={true}
10421042
/>
10431043
</div>
1044-
) : buffer.type === "webViewer" ? (
1045-
<div
1046-
className={
1047-
isActiveBuffer ? "h-full w-full" : "pointer-events-none h-full w-full"
1048-
}
1049-
>
1044+
) : buffer.type === "webViewer" && isActiveBuffer ? (
1045+
<div className="h-full w-full">
10501046
<WebViewer
10511047
url={buffer.url}
10521048
bufferId={buffer.id}

src/features/web-viewer/hooks/use-embedded-webview.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { invoke } from "@tauri-apps/api/core";
22
import { getCurrentWebview } from "@tauri-apps/api/webview";
33
import { useCallback, useEffect, useRef, useState, type RefObject } from "react";
44
import { hasOverlayCoveringWebview } from "../utils/web-viewer-overlay";
5+
import { shouldShowEmbeddedWebview } from "../utils/embedded-webview-visibility";
56

67
interface UseEmbeddedWebviewOptions {
78
bufferId: string;
@@ -110,9 +111,16 @@ export function useEmbeddedWebview({
110111

111112
const syncWebviewVisibility = useCallback(
112113
async (label: string) => {
113-
await setWebviewVisible(label, isVisible && !overlayHiddenRef.current);
114+
await setWebviewVisible(
115+
label,
116+
shouldShowEmbeddedWebview({
117+
isActive,
118+
isVisible,
119+
overlayHidden: overlayHiddenRef.current,
120+
}),
121+
);
114122
},
115-
[isVisible, setWebviewVisible],
123+
[isActive, isVisible, setWebviewVisible],
116124
);
117125

118126
useEffect(() => {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
import { shouldShowEmbeddedWebview } from "../utils/embedded-webview-visibility";
3+
4+
describe("embedded webview visibility", () => {
5+
it("shows only the active visible webview", () => {
6+
expect(
7+
shouldShowEmbeddedWebview({
8+
isActive: true,
9+
isVisible: true,
10+
overlayHidden: false,
11+
}),
12+
).toBe(true);
13+
});
14+
15+
it("hides inactive webviews even when their pane content is visible", () => {
16+
expect(
17+
shouldShowEmbeddedWebview({
18+
isActive: false,
19+
isVisible: true,
20+
overlayHidden: false,
21+
}),
22+
).toBe(false);
23+
});
24+
25+
it("hides active webviews behind app overlays", () => {
26+
expect(
27+
shouldShowEmbeddedWebview({
28+
isActive: true,
29+
isVisible: true,
30+
overlayHidden: true,
31+
}),
32+
).toBe(false);
33+
});
34+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
interface EmbeddedWebviewVisibilityState {
2+
isActive: boolean;
3+
isVisible: boolean;
4+
overlayHidden: boolean;
5+
}
6+
7+
export function shouldShowEmbeddedWebview({
8+
isActive,
9+
isVisible,
10+
overlayHidden,
11+
}: EmbeddedWebviewVisibilityState): boolean {
12+
return isActive && isVisible && !overlayHidden;
13+
}

0 commit comments

Comments
 (0)