дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-20 08:35:42 +02:00
Порівняти коміти
1
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
21387db207 |
No files matched your search
@@ -180,29 +180,6 @@ unsafe extern "C-unwind" fn should_terminate(_this: *mut AnyObject, _selector: S
|
||||
|
||||
static APP: std::sync::OnceLock<AppHandle> = std::sync::OnceLock::new();
|
||||
|
||||
/// Escape the page leaves unhandled reaches the window as `cancelOperation:`, on which NSWindow
|
||||
/// leaves full screen, so pressing Escape once more after closing a popup left full screen. The
|
||||
/// IDE's windows answer it with nothing; View › Appearance › Toggle Full Screen (⌃⌘F) leaves it.
|
||||
pub fn keep_full_screen_on_escape() {
|
||||
static ONCE: std::sync::Once = std::sync::Once::new();
|
||||
ONCE.call_once(|| unsafe {
|
||||
let Some(class) = AnyClass::get(c"TaoWindow") else {
|
||||
tracing::warn!("no TaoWindow class: Escape leaves full screen");
|
||||
return;
|
||||
};
|
||||
let imp: Imp = std::mem::transmute(ignore_cancel_operation as CancelOperation);
|
||||
let class = class as *const AnyClass as *mut AnyClass;
|
||||
let added = objc2::ffi::class_addMethod(class, objc2::sel!(cancelOperation:), imp, c"v@:@".as_ptr());
|
||||
if !added.as_bool() {
|
||||
tracing::warn!("could not handle cancelOperation:");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
type CancelOperation = unsafe extern "C-unwind" fn(*mut AnyObject, Sel, *mut AnyObject);
|
||||
|
||||
unsafe extern "C-unwind" fn ignore_cancel_operation(_this: *mut AnyObject, _selector: Sel, _sender: *mut AnyObject) {}
|
||||
|
||||
/// Whether AppKit is handling a key press right now. A menu item performed at this point
|
||||
/// was chosen by its key equivalent: a click, arrow keys plus Return and accessibility
|
||||
/// presses all run with a non-key current event.
|
||||
|
||||
@@ -730,8 +730,6 @@ fn build_project_window(app: &AppHandle, mut config: WindowConfig) -> IdeResult<
|
||||
decorate_csd(&window);
|
||||
#[cfg(target_os = "macos")]
|
||||
crate::page_swipe::install(&window);
|
||||
#[cfg(target_os = "macos")]
|
||||
crate::macos::keep_full_screen_on_escape();
|
||||
apply_zoom(app, &window);
|
||||
#[cfg(target_os = "macos")]
|
||||
align_titlebar(app, &window, app.try_state::<WindowsState>().is_some_and(|w| w.opens_project(window.label())));
|
||||
|
||||
@@ -28,6 +28,7 @@ import { call, commands, isTauri } from "./platform/ipc";
|
||||
import { hideSplash } from "./platform/splash";
|
||||
import { prefetchLazyComponents } from "./ui";
|
||||
import { installWindowDrag } from "./workbench/window-drag";
|
||||
import { installFullscreenEscapeGuard } from "./workbench/fullscreenEscape";
|
||||
|
||||
if (import.meta.env.DEV && isTauri()) {
|
||||
// The Tauri MCP bridge returns eval results via `window.__TAURI__` on Windows/Linux
|
||||
@@ -71,6 +72,8 @@ if (aux?.kind === "settings") {
|
||||
activateSecondaryWindow();
|
||||
activateDeploymentWindowFeatures(aux.parent);
|
||||
} else {
|
||||
// Before the features' and the dispatcher's key handlers: it wraps the Escape they see.
|
||||
installFullscreenEscapeGuard();
|
||||
activateWorkbench();
|
||||
// `vite build --mode perf` is a production bundle for the performance harness (`perf/`).
|
||||
const perfBuild = import.meta.env.MODE === "perf";
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* macOS: an Escape key press the page leaves unhandled (not default-prevented) goes back from
|
||||
* WebKit to AppKit as the web view's `cancelOperation:`, and AppKit answers it in a full-screen
|
||||
* window by leaving full screen, so pressing Escape once more after closing a popup dropped the
|
||||
* IDE out of full screen. While this window is in full screen, Escape is marked handled after
|
||||
* everything else has seen it; View › Appearance › Toggle Full Screen (⌃⌘F) leaves full screen.
|
||||
*/
|
||||
import { commands, isTauri, onIdeEvent } from "@/platform/ipc";
|
||||
import { usePlatform } from "@/platform/platformInfo";
|
||||
|
||||
/** Installs the guard on `target`; `isFullscreen` is this window's state (tests pass their own). */
|
||||
export function installFullscreenEscapeGuard(
|
||||
target: Window = window,
|
||||
isFullscreen: () => boolean = trackFullscreen(),
|
||||
): () => void {
|
||||
const onCapture = (e: KeyboardEvent) => {
|
||||
if (e.key !== "Escape" || e.isComposing || usePlatform.getState().os !== "macos" || !isFullscreen()) return;
|
||||
// Runs last in the bubble phase: handlers that check `defaultPrevented` see the event as it was.
|
||||
const handled = () => e.preventDefault();
|
||||
target.addEventListener("keydown", handled, { once: true });
|
||||
// A handler that stops the event has handled it; the bubble listener above won't run then.
|
||||
for (const name of ["stopPropagation", "stopImmediatePropagation"] as const) {
|
||||
const stop = e[name].bind(e);
|
||||
e[name] = () => {
|
||||
target.removeEventListener("keydown", handled);
|
||||
e.preventDefault();
|
||||
stop();
|
||||
};
|
||||
}
|
||||
};
|
||||
// Capture on the window before anything else is installed: it runs first.
|
||||
target.addEventListener("keydown", onCapture, true);
|
||||
return () => target.removeEventListener("keydown", onCapture, true);
|
||||
}
|
||||
|
||||
function trackFullscreen(): () => boolean {
|
||||
let fullscreen = false;
|
||||
if (!isTauri()) return () => fullscreen;
|
||||
const sync = () =>
|
||||
void commands
|
||||
.windowIsFullscreen()
|
||||
.then((on) => (fullscreen = on))
|
||||
.catch(() => {});
|
||||
sync();
|
||||
onIdeEvent("windowFullscreenChanged", sync);
|
||||
return () => fullscreen;
|
||||
}
|
||||
Reference in new issue
Заблокувати користувача