mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
Escape the page leaves unhandled goes back from WebKit as the web view's doCommandBySelector:(cancelOperation:), run through NSView's own implementation, which leaves full screen directly; the window-level cancelOperation: hook from #3134 was never reached and is removed. In macOS full screen the workbench now marks Escape handled after every key handler has seen it (also when one stops it); Ctrl+Cmd+F leaves full screen. Refs #3970, #3104
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
import { usePlatform } from "@/platform/platformInfo";
|
|
import { installFullscreenEscapeGuard } from "./fullscreenEscape";
|
|
|
|
let fullscreen = true;
|
|
let dispose = () => {};
|
|
const escape = (target: EventTarget) => {
|
|
const e = new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true });
|
|
target.dispatchEvent(e);
|
|
return e;
|
|
};
|
|
|
|
beforeEach(() => {
|
|
fullscreen = true;
|
|
usePlatform.setState({ os: "macos" });
|
|
dispose = installFullscreenEscapeGuard(window, () => fullscreen);
|
|
});
|
|
afterEach(() => {
|
|
dispose();
|
|
document.body.replaceChildren();
|
|
});
|
|
|
|
describe("Escape in full screen", () => {
|
|
it("is marked handled when nothing handles it, so the window stays in full screen", () => {
|
|
expect(escape(document.body).defaultPrevented).toBe(true);
|
|
});
|
|
|
|
it("is marked handled when a handler stops it", () => {
|
|
const popup = document.body.appendChild(document.createElement("div"));
|
|
popup.addEventListener("keydown", (e) => e.stopPropagation());
|
|
expect(escape(popup).defaultPrevented).toBe(true);
|
|
// The next key press is not affected by a listener left behind.
|
|
fullscreen = false;
|
|
expect(escape(document.body).defaultPrevented).toBe(false);
|
|
});
|
|
|
|
it("reaches other handlers not yet default-prevented", () => {
|
|
let seen: boolean | null = null;
|
|
const onKey = (e: KeyboardEvent) => (seen = e.defaultPrevented);
|
|
window.addEventListener("keydown", onKey);
|
|
escape(document.body);
|
|
window.removeEventListener("keydown", onKey);
|
|
expect(seen).toBe(false);
|
|
});
|
|
|
|
it("is left alone outside full screen and on other systems", () => {
|
|
fullscreen = false;
|
|
expect(escape(document.body).defaultPrevented).toBe(false);
|
|
fullscreen = true;
|
|
usePlatform.setState({ os: "windows" });
|
|
expect(escape(document.body).defaultPrevented).toBe(false);
|
|
});
|
|
});
|