дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
fix(profiler): keep Escape in the focused zoomed flame graph
Цей коміт міститься в:
1 джерело
6d42597038
коміт
07e5ec7c0b
2 files changed
+39
-1
No files matched your search
@@ -1,8 +1,10 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { render, screen, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { registerAction } from "@/platform/actions";
|
||||
import type { Profile, ProfileMode } from "@/platform/ipc";
|
||||
import { useI18n } from "@/platform/i18n";
|
||||
import { installKeyboardDispatcher } from "@/platform/keymap";
|
||||
import { ProfilerTabs, ProfilerView } from "./ProfilerView";
|
||||
import { addSnapshot, resetProfiler, useProfiler } from "./store";
|
||||
|
||||
@@ -99,6 +101,37 @@ describe("ProfilerView", () => {
|
||||
expect(screen.getByText("Zoomed into Main.run")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("reserves Escape ahead of the workbench only when the zoomed graph has focus", async () => {
|
||||
addSnapshot("App", profile("cpu", 120));
|
||||
const focusEditor = vi.fn();
|
||||
const unregister = registerAction({ id: "toolwindow.focusEditor", title: "Focus Editor", run: focusEditor });
|
||||
const uninstall = installKeyboardDispatcher();
|
||||
try {
|
||||
render(<ProfilerView />);
|
||||
const user = userEvent.setup();
|
||||
const graph = screen.getByRole("tree", { name: "Flame graph" });
|
||||
graph.focus();
|
||||
await user.keyboard("{ArrowDown}{Enter}");
|
||||
expect(screen.getByText("Zoomed into Main.run")).toBeInTheDocument();
|
||||
|
||||
screen.getByRole("textbox", { name: "Search frames" }).focus();
|
||||
await user.keyboard("{Escape}");
|
||||
expect(focusEditor).toHaveBeenCalledOnce();
|
||||
expect(screen.getByText("Zoomed into Main.run")).toBeInTheDocument();
|
||||
|
||||
graph.focus();
|
||||
await user.keyboard("{Escape}");
|
||||
expect(screen.queryByText("Zoomed into Main.run")).not.toBeInTheDocument();
|
||||
expect(focusEditor).toHaveBeenCalledOnce();
|
||||
expect(graph).toHaveFocus();
|
||||
await user.keyboard("{Escape}");
|
||||
expect(focusEditor).toHaveBeenCalledTimes(2);
|
||||
} finally {
|
||||
uninstall();
|
||||
unregister();
|
||||
}
|
||||
});
|
||||
|
||||
it("allocation profile shows bytes and marks type frames", () => {
|
||||
addSnapshot("App", profile("allocations", 640_000_000));
|
||||
useProfiler.setState({ tab: "tree" });
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { useCallback, useId, useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent } from "react";
|
||||
import clsx from "clsx";
|
||||
import type { Profile } from "@/platform/ipc";
|
||||
import { registerKeyClaim } from "@/platform/keymap";
|
||||
import { EmptyState, Icon, IconButton, Input, Tabs, Tree, T } from "@/ui";
|
||||
import { editorService } from "@/workbench/contributions";
|
||||
import { colorSlot, flameLayout, formatWeight, frameLocation, matchingFrames, parentIndex, share } from "./model";
|
||||
@@ -113,6 +114,10 @@ function FlameGraph({ profile, query }: { profile: Profile; query: string }) {
|
||||
}
|
||||
}, [activeId]);
|
||||
useLayoutEffect(scrollToActive, [scrollToActive, layout.depth]);
|
||||
useLayoutEffect(() => {
|
||||
if (zoom === 0) return;
|
||||
return registerKeyClaim((event, stroke) => stroke === "Escape" && event.target === graphRef.current);
|
||||
}, [zoom]);
|
||||
|
||||
const zoomTo = (node: number) => {
|
||||
setZoom(node);
|
||||
|
||||
Reference in new issue
Заблокувати користувача