Skip to content

Commit f9c24f7

Browse files
committed
feat(design-mode): exit to pure-code mode when LP wasn't open at entry
The design-mode toggle now remembers whether live preview was open when entering. If LP was already open the exit behavior is unchanged — LP stays visible at its prior width. If LP was closed and got opened only because design mode needed it, exiting closes LP again and main-toolbar shrinks back to the icon-bar width, returning the user to the pure code-editing layout they started from. The skipToolbarRestore path (LP was just closed by the user via toolbar-go-live) is unaffected — no double-close. Updates section-5 tests so the two branches are explicit mirrors of each other: LP-was-open keeps LP visible with toolbar at LP width; LP-wasn't-open closes LP with toolbar at icon-bar width.
1 parent de12d6d commit f9c24f7

2 files changed

Lines changed: 34 additions & 10 deletions

File tree

src/view/CentralControlBar.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,20 @@ define(function (require, exports, module) {
271271
}
272272
_applyCollapsedLayout();
273273
} else {
274-
_restoreExpandedLayout(skipToolbarRestore);
274+
// If live preview was NOT open before we entered design mode,
275+
// exit into pure-code mode by closing it again. Snapshot the
276+
// entry state before _restoreExpandedLayout resets it.
277+
// skipToolbarRestore is already the LP-just-closed path, so
278+
// don't double-close in that case. _restoreExpandedLayout runs
279+
// first so our !important geometry overrides are cleared before
280+
// WorkspaceManager resizes #main-toolbar to the no-panel state.
281+
const shouldCloseLivePreview = !skipToolbarRestore &&
282+
!livePreviewWasOpen &&
283+
_isLivePreviewOpen();
284+
_restoreExpandedLayout(shouldCloseLivePreview ? true : skipToolbarRestore);
285+
if (shouldCloseLivePreview) {
286+
CommandManager.execute(Commands.FILE_LIVE_FILE_PREVIEW);
287+
}
275288
}
276289
}
277290

test/spec/CentralControlBar-integ-test.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,19 @@ define(function (require, exports, module) {
570570
"sidebar to settle at baseline 200px", 2000);
571571
});
572572

573-
it("should leave Live Preview open after exit", async function () {
573+
it("should leave Live Preview open after exit when LP was already open at entry", async function () {
574+
// Mirror of the "LP was opened by the toggle" test below: when
575+
// the user already had LP open, exiting design mode must keep
576+
// LP visible and main-toolbar at a real LP-panel width (well
577+
// above the icon-bar width).
574578
await openLivePreview();
575579
await enterDesignMode();
576580
await exitDesignMode();
581+
577582
expect(livePanel().isVisible()).toBe(true);
583+
const iconsW = _$("#plugin-icons-bar").outerWidth();
584+
const toolbarW = _$("#main-toolbar").outerWidth();
585+
expect(toolbarW).toBeGreaterThan(iconsW + 50);
578586
});
579587

580588
it("should fit sidebar + CCB + toolbar + a reasonable editor area in the window after exit", async function () {
@@ -591,17 +599,20 @@ define(function (require, exports, module) {
591599
expect(testWindow.innerWidth - total).toBeGreaterThan(100);
592600
});
593601

594-
it("should use the innerWidth/2.5 default for toolbar when LP was opened by the toggle itself", async function () {
595-
// LP is closed on entry — the toggle opens it.
602+
it("should close Live Preview and shrink toolbar to the icon-bar width when LP was opened by the toggle itself", async function () {
603+
// LP is closed on entry — the toggle opens it. On exit we
604+
// restore the original "pure code" layout: LP closes again
605+
// and main-toolbar shrinks to the icon-bar width.
596606
await enterDesignMode();
607+
expect(livePanel().isVisible()).toBe(true);
597608
await exitDesignMode();
598609

599-
expect(livePanel().isVisible()).toBe(true);
600-
const expectedDefault = Math.floor(testWindow.innerWidth / 2.5);
601-
// `_restoreExpandedLayout` may trim a bit to honour the MIN_EDITOR clamp
602-
// on narrow viewports, so compare with a generous tolerance.
603-
const toolbar = _$("#main-toolbar").outerWidth();
604-
expect(Math.abs(toolbar - expectedDefault)).toBeLessThan(30);
610+
await awaitsFor(function () { return !livePanel().isVisible(); },
611+
"live preview to close on exit", 5000);
612+
613+
const iconsW = _$("#plugin-icons-bar").outerWidth();
614+
const toolbarW = _$("#main-toolbar").outerWidth();
615+
expect(Math.abs(toolbarW - iconsW)).toBeLessThan(3);
605616
});
606617

607618
it("should not let the sidebar snap wider than the rendered (capped) width after exit even if user dragged past the cap in design mode", async function () {

0 commit comments

Comments
 (0)