Skip to content

Commit e0429ed

Browse files
committed
fix(editor): keep the preset mark on a visible row during a rename
The row being renamed is a name form, so it cannot carry the active mark: with a matching twin the menu showed a match and no check at all. The mark now skips it.
1 parent 1d1c01a commit e0429ed

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎src/components/ai-edition/StylePresetsMenu.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,14 @@ export function StylePresetsMenu() {
179179
// At most ONE row reads as active. Several entries can carry the same look — the same
180180
// look saved twice under two names — and a radio group lighting two of them reads as
181181
// broken. First match wins, in menu order (the built-in row leads, then the saved ones).
182+
// The row being renamed is a name form for the moment, so it cannot carry the mark: a
183+
// matching twin takes it instead of the menu showing a match and no check at all.
184+
const renamingId = mode.kind === "rename" ? mode.id : null;
182185
const activeId = sameStylePresetLook(factory, current)
183186
? FACTORY_STYLE_PRESET_ID
184-
: (presets.find((preset) => sameStylePresetLook(preset.appearance, current))?.id ?? null);
187+
: (presets.find(
188+
(preset) => preset.id !== renamingId && sameStylePresetLook(preset.appearance, current),
189+
)?.id ?? null);
185190

186191
const apply = async (appearance: StylePresetAppearance, name: string) => {
187192
setOpen(false);

‎src/components/ai-edition/v4/EditorTopBar.stylePresets.test.tsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,20 @@ describe("Presets menu in the editor top bar", () => {
244244
expect(checked.map((row) => row.textContent)).toEqual(["Warm"]);
245245
});
246246

247+
it("keeps a twin checked while the matching row is being renamed", async () => {
248+
state.presets.list = vi.fn<Fn>(async () => [WARM, { ...WARM, id: "Twin", name: "Twin" }]);
249+
state.settings = { ...DEFAULT_EDITOR_SETTINGS, padding: 42, wallpaper: "#aa5500" };
250+
renderPane();
251+
await openMenu();
252+
openRowActions("Warm");
253+
fireEvent.click(screen.getByRole("menuitem", { name: "Rename" }));
254+
// Warm's row is a name form now, so the mark sits on the twin that still matches.
255+
const checked = within(screen.getByRole("menu", { name: "Style presets" }))
256+
.getAllByRole("menuitemradio")
257+
.filter((row) => row.getAttribute("aria-checked") === "true");
258+
expect(checked.map((row) => row.textContent)).toEqual(["Twin"]);
259+
});
260+
247261
it("opens a row's actions from “⋯” without applying the preset", async () => {
248262
renderPane();
249263
await openMenu();

0 commit comments

Comments
 (0)