Skip to content

Commit 2c1430c

Browse files
committed
feat(design-mode): toolbar-go-live in design mode exits to LP-visible
Clicking #toolbar-go-live while in design mode now exits design mode and leaves Live Preview open, instead of hiding LP and dropping back to pure code mode. Outside design mode the button still toggles LP as before. Implemented as a capture-phase click listener on #toolbar-go-live that stops propagation when editorCollapsed is true and calls _setEditorCollapsed(false, { keepLivePreviewOpen: true }), forcing the exit path to keep LP regardless of the entry-state snapshot. Section-6 tests now cover both branches: in design mode the click exits with LP visible at LP width; outside design mode the click hides LP normally. Uses native el.click() so the capture-phase listener actually fires (jQuery's synthetic .trigger("click") would skip it).
1 parent 45e9eb8 commit 2c1430c

2 files changed

Lines changed: 51 additions & 13 deletions

File tree

src/view/CentralControlBar.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,15 @@ define(function (require, exports, module) {
275275
// exit into pure-code mode by closing it again. Snapshot the
276276
// entry state before _restoreExpandedLayout resets it.
277277
// 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.
278+
// don't double-close in that case. opts.keepLivePreviewOpen
279+
// is the "intercepted #toolbar-go-live click" path — caller
280+
// wants LP to stay regardless of entry state. _restoreExpandedLayout
281+
// runs first so our !important geometry overrides are cleared
282+
// before WorkspaceManager resizes #main-toolbar to the no-panel
283+
// state.
284+
const keepLivePreviewOpen = !!(opts && opts.keepLivePreviewOpen);
281285
const shouldCloseLivePreview = !skipToolbarRestore &&
286+
!keepLivePreviewOpen &&
282287
!livePreviewWasOpen &&
283288
_isLivePreviewOpen();
284289
_restoreExpandedLayout(shouldCloseLivePreview ? true : skipToolbarRestore);
@@ -337,6 +342,25 @@ define(function (require, exports, module) {
337342
$("#ccbUndoBtn").attr("title", Strings.CMD_UNDO);
338343
$("#ccbRedoBtn").attr("title", Strings.CMD_REDO);
339344
$("#ccbSaveBtn").attr("title", Strings.CMD_FILE_SAVE);
345+
346+
// Intercept clicks on #toolbar-go-live while in design mode: instead
347+
// of letting the live-preview module hide LP (the default toggle
348+
// behaviour), we exit design mode and keep LP visible. Outside
349+
// design mode the button continues to toggle LP normally — we only
350+
// act when `editorCollapsed` is true. Capture phase + stopImmediate-
351+
// Propagation guarantees we run before the live-preview module's
352+
// jQuery click handler.
353+
const goLiveBtn = document.getElementById("toolbar-go-live");
354+
if (goLiveBtn) {
355+
goLiveBtn.addEventListener("click", function (e) {
356+
if (!editorCollapsed) {
357+
return;
358+
}
359+
e.stopImmediatePropagation();
360+
e.preventDefault();
361+
_setEditorCollapsed(false, { keepLivePreviewOpen: true });
362+
}, true /* useCapture */);
363+
}
340364
_syncLeftPositions();
341365

342366
// While the sidebar is being dragged we only reposition CCB / main-toolbar.

test/spec/CentralControlBar-integ-test.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -654,27 +654,41 @@ define(function (require, exports, module) {
654654
});
655655
});
656656

657-
describe("6. Exit triggered by hiding live preview", function () {
657+
describe("6. #toolbar-go-live click in design mode", function () {
658658

659-
it("should exit design mode, hide LP, and shrink main-toolbar to the icon-bar width when #toolbar-go-live is clicked in design mode", async function () {
659+
it("should exit design mode and keep Live Preview visible when #toolbar-go-live is clicked in design mode", async function () {
660660
await openLivePreview();
661661
await enterDesignMode();
662662
expect(WorkspaceManager.isInDesignMode()).toBe(true);
663663
expect(livePanel().isVisible()).toBe(true);
664664

665-
_$("#toolbar-go-live").trigger("click");
665+
// Native click — CCB intercepts via a capture-phase listener,
666+
// which jQuery's `.trigger("click")` would not exercise.
667+
_$("#toolbar-go-live")[0].click();
666668

667-
// LP hides → visible to the user.
668-
await awaitsFor(function () { return !livePanel().isVisible(); },
669-
"live preview to hide", 5000);
670-
// And the editor chrome comes back — design mode ends.
669+
// Design mode ends — editor chrome comes back.
671670
await awaitsFor(function () { return !WorkspaceManager.isInDesignMode(); },
672-
"design mode to deactivate after LP close", 5000);
671+
"design mode to deactivate after toolbar-go-live click", 5000);
672+
// LP should remain open — the click in design mode must NOT hide it.
673+
expect(livePanel().isVisible()).toBe(true);
673674

674-
// Main-toolbar should end up at the icon-bar-only width (its no-panel state).
675+
// Main-toolbar should be at a real LP-panel width (well above
676+
// just the icon-bar width).
675677
const iconsW = _$("#plugin-icons-bar").outerWidth();
676678
const toolbarW = _$("#main-toolbar").outerWidth();
677-
expect(Math.abs(toolbarW - iconsW)).toBeLessThan(3);
679+
expect(toolbarW).toBeGreaterThan(iconsW + 50);
680+
});
681+
682+
it("should toggle Live Preview off normally when #toolbar-go-live is clicked outside design mode", async function () {
683+
await openLivePreview();
684+
expect(WorkspaceManager.isInDesignMode()).toBe(false);
685+
expect(livePanel().isVisible()).toBe(true);
686+
687+
_$("#toolbar-go-live")[0].click();
688+
689+
await awaitsFor(function () { return !livePanel().isVisible(); },
690+
"live preview to hide on toolbar-go-live click", 5000);
691+
expect(WorkspaceManager.isInDesignMode()).toBe(false);
678692
});
679693
});
680694

0 commit comments

Comments
 (0)