diff --git a/src/BloomBrowserUI/bookEdit/toolbox/canvas/customXmatterPage.tsx b/src/BloomBrowserUI/bookEdit/toolbox/canvas/customXmatterPage.tsx index 927dd4e7534a..9d54f8084b3c 100644 --- a/src/BloomBrowserUI/bookEdit/toolbox/canvas/customXmatterPage.tsx +++ b/src/BloomBrowserUI/bookEdit/toolbox/canvas/customXmatterPage.tsx @@ -6,6 +6,7 @@ import { CustomPageLayoutMenu } from "./customPageLayoutMenu"; import { CanvasElementManager, kBackgroundImageClass, + showCanvasTool, theOneCanvasElementManager, } from "../../js/CanvasElementManager"; import { EditableDivUtils } from "../../js/editableDivUtils"; @@ -60,9 +61,7 @@ import { isLegacyThemeCssLoaded } from "../../bookSettings/appearanceThemeUtils" visibility of different languages. */ -export async function convertXmatterPageToCustom( - page: HTMLElement, -): Promise { +async function convertXmatterPageToCustom(page: HTMLElement): Promise { const marginBox = page.getElementsByClassName( "marginBox", )[0] as HTMLElement; @@ -257,6 +256,8 @@ function finishReactivatingPage(page: HTMLElement): void { theOneCanvasElementManager.turnOnCanvasElementEditing(); ensureDerivedFieldsFitOnCustomPage(page); getToolboxBundleExports()?.applyToolboxStateToPage(); + // Enable or show the canvas tool. + showCanvasTool(); } // This function tries to make sure that all derived-field canvas elements fit on the page. @@ -441,6 +442,10 @@ function renderPageLayoutMenu(page: HTMLElement, container: HTMLElement): void { () => convertXmatterPageToCustom(page), "customPageLayout-convertStartOver", ); + // This is normally set in editView/toggleCustomPageLayout, but we're not calling that. + // The attribute will be persisted only if some other change is made to the page, but that + // may be good enough since the user is starting over and presumably will make some changes. + page.setAttribute("data-tool-id", "canvas"); renderPageLayoutMenu(page, container); return; } @@ -461,6 +466,10 @@ function renderPageLayoutMenu(page: HTMLElement, container: HTMLElement): void { () => convertXmatterPageToCustom(page), "customPageLayout-convertFirstTime", ); + // Set data-tool-id on the browser DOM so it persists when jumpToPage saves. + // (The C# toggleCustomPageLayout set it on the C# DOM, but returned early + // without SaveThen, so that change would be overwritten by the browser save.) + page.setAttribute("data-tool-id", "canvas"); // Persist the newly created custom layout state so a later toggle back // to standard has matching server-side state to work from. await postString( @@ -468,6 +477,8 @@ function renderPageLayoutMenu(page: HTMLElement, container: HTMLElement): void { page.getAttribute("id")!, ); renderPageLayoutMenu(page, container); + } else if (selection === "custom" && response) { + showCanvasTool(); // otherwise called from convertXmatterPageToCustom()/finishReactivatingPage() } }} />, diff --git a/src/BloomExe/web/controllers/EditingViewApi.cs b/src/BloomExe/web/controllers/EditingViewApi.cs index f6af7d3c507e..19d6ed509e73 100644 --- a/src/BloomExe/web/controllers/EditingViewApi.cs +++ b/src/BloomExe/web/controllers/EditingViewApi.cs @@ -186,6 +186,11 @@ private void HandleToggleCustomCover(ApiRequest request) request.ReplyWithText("false"); return; } + pageElt.SetAttribute("data-tool-id", "canvas"); + } + else + { + pageElt.RemoveAttribute("data-tool-id"); } request.ReplyWithText("true"); @@ -200,6 +205,7 @@ private void HandleToggleCustomCover(ApiRequest request) // page element. var backgroundAudio = pageElt.GetAttribute(HtmlDom.musicAttrName); var backgroundAudioVolume = pageElt.GetAttribute(HtmlDom.musicVolumeName); + var dataToolId = pageElt.GetAttribute("data-tool-id"); // Bring everything up to date consistent with the new // state. Might be enough just do the BookData update. book.EnsureUpToDateMemory(new NullProgress()); @@ -223,6 +229,11 @@ private void HandleToggleCustomCover(ApiRequest request) // Keep the same invariant we enforce elsewhere. if (string.IsNullOrEmpty(backgroundAudio)) updatedPageElt.RemoveAttribute(HtmlDom.musicVolumeName); + + if (string.IsNullOrEmpty(dataToolId)) + updatedPageElt.RemoveAttribute("data-tool-id"); + else + updatedPageElt.SetAttribute("data-tool-id", dataToolId); } return pageId;