Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(editor): keep the preset mark on a visible row during a rename

EtienneLescote0429edc2c30
diff --git a/src/components/ai-edition/StylePresetsMenu.tsx b/src/components/ai-edition/StylePresetsMenu.tsx
index 3e5010eee..f5efec2ab 100644
--- a/src/components/ai-edition/StylePresetsMenu.tsx
+++ b/src/components/ai-edition/StylePresetsMenu.tsx
@@ -179,9 +179,14 @@ export function StylePresetsMenu() {
// At most ONE row reads as active. Several entries can carry the same look — the same
// look saved twice under two names — and a radio group lighting two of them reads as
// broken. First match wins, in menu order (the built-in row leads, then the saved ones).
+ // The row being renamed is a name form for the moment, so it cannot carry the mark: a
+ // matching twin takes it instead of the menu showing a match and no check at all.
+ const renamingId = mode.kind === "rename" ? mode.id : null;
const activeId = sameStylePresetLook(factory, current)
? FACTORY_STYLE_PRESET_ID
- : (presets.find((preset) => sameStylePresetLook(preset.appearance, current))?.id ?? null);
+ : (presets.find(
+ (preset) => preset.id !== renamingId && sameStylePresetLook(preset.appearance, current),
+ )?.id ?? null);
const apply = async (appearance: StylePresetAppearance, name: string) => {
setOpen(false);
diff --git a/src/components/ai-edition/v4/EditorTopBar.stylePresets.test.tsx b/src/components/ai-edition/v4/EditorTopBar.stylePresets.test.tsx
index 199d70aa2..074542471 100644
--- a/src/components/ai-edition/v4/EditorTopBar.stylePresets.test.tsx
+++ b/src/components/ai-edition/v4/EditorTopBar.stylePresets.test.tsx
@@ -244,6 +244,20 @@ describe("Presets menu in the editor top bar", () => {
expect(checked.map((row) => row.textContent)).toEqual(["Warm"]);
});
+ it("keeps a twin checked while the matching row is being renamed", async () => {
+ state.presets.list = vi.fn<Fn>(async () => [WARM, { ...WARM, id: "Twin", name: "Twin" }]);
+ state.settings = { ...DEFAULT_EDITOR_SETTINGS, padding: 42, wallpaper: "#aa5500" };
+ renderPane();
+ await openMenu();
+ openRowActions("Warm");
+ fireEvent.click(screen.getByRole("menuitem", { name: "Rename" }));
+ // Warm's row is a name form now, so the mark sits on the twin that still matches.
+ const checked = within(screen.getByRole("menu", { name: "Style presets" }))
+ .getAllByRole("menuitemradio")
+ .filter((row) => row.getAttribute("aria-checked") === "true");
+ expect(checked.map((row) => row.textContent)).toEqual(["Twin"]);
+ });
+
it("opens a row's actions from “⋯” without applying the preset", async () => {
renderPane();
await openMenu();