Skip to content

Commit 8e826eb

Browse files
committed
feat: make no-distractions mode work cleanly in design mode
Expose WorkspaceManager.isInDesignMode() / setDesignMode() and a new EVENT_WORKSPACE_DESIGN_MODE_CHANGE so other modules can react to the full-live-preview layout without reaching into the control bar. CentralControlBar mirrors its editorCollapsed flag into the workspace manager on every toggle. NoDistractions now checks isInDesignMode(): in design mode entering/exiting only toggles the sidebar (the main toolbar and panels are part of the editing surface and hiding them would blank the live preview area). In the normal editor layout the previous behavior — hide sidebar + main toolbar + panels — still applies.
1 parent 7c278a1 commit 8e826eb

3 files changed

Lines changed: 61 additions & 6 deletions

File tree

src/extensionsIntegrated/NoDistractions/main.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,27 @@ define(function (require, exports, module) {
168168
KeyBindingManager.addBinding(CMD_TOGGLE_PANELS, [ {key: togglePanelsKey_EN}, {key: togglePanelsKeyMac_EN, platform: "mac"} ]);
169169

170170
PreferencesManager.on("change", PREFS_PURE_CODE, function () {
171+
const inDesignMode = WorkspaceManager.isInDesignMode &&
172+
WorkspaceManager.isInDesignMode();
171173
if (PreferencesManager.get(PREFS_PURE_CODE)) {
172-
ViewUtils.hideMainToolBar();
173-
CommandManager.execute(Commands.HIDE_SIDEBAR);
174-
_hidePanelsIfRequired();
174+
if (inDesignMode) {
175+
// In design mode the live preview already fills the editor
176+
// area and the main toolbar is the visible surface; just
177+
// collapse the sidebar so LP can stretch to the full width.
178+
CommandManager.execute(Commands.HIDE_SIDEBAR);
179+
} else {
180+
ViewUtils.hideMainToolBar();
181+
CommandManager.execute(Commands.HIDE_SIDEBAR);
182+
_hidePanelsIfRequired();
183+
}
175184
} else {
176-
ViewUtils.showMainToolBar();
177-
CommandManager.execute(Commands.SHOW_SIDEBAR);
178-
_showPanelsIfRequired();
185+
if (inDesignMode) {
186+
CommandManager.execute(Commands.SHOW_SIDEBAR);
187+
} else {
188+
ViewUtils.showMainToolBar();
189+
CommandManager.execute(Commands.SHOW_SIDEBAR);
190+
_showPanelsIfRequired();
191+
}
179192
}
180193
_updateCheckedState();
181194
});

src/view/CentralControlBar.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ define(function (require, exports, module) {
242242
if (_toggleDesignModeCommand) {
243243
_toggleDesignModeCommand.setChecked(editorCollapsed);
244244
}
245+
if (WorkspaceManager.setDesignMode) {
246+
WorkspaceManager.setDesignMode(editorCollapsed);
247+
}
245248

246249
if (editorCollapsed) {
247250
livePreviewWasOpen = _isLivePreviewOpen();

src/view/WorkspaceManager.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ define(function (require, exports, module) {
7474
*/
7575
const EVENT_WORKSPACE_PANEL_HIDDEN = PanelView.EVENT_PANEL_HIDDEN;
7676

77+
/**
78+
* Event triggered when design mode (editor collapsed, full live preview) is
79+
* entered or exited. Payload: `(active: boolean)`.
80+
* @const
81+
*/
82+
const EVENT_WORKSPACE_DESIGN_MODE_CHANGE = "workspaceDesignModeChange";
83+
7784
/**
7885
* Width of the main toolbar in pixels.
7986
* @const
@@ -619,6 +626,35 @@ define(function (require, exports, module) {
619626
recomputeLayout(true);
620627
}
621628

629+
// Design mode tracks whether the editor is fully collapsed to show only the
630+
// live-preview panel. The flag is owned by view/CentralControlBar but mirrored
631+
// here so other modules don't need to reach into the control bar.
632+
let _isInDesignMode = false;
633+
634+
/**
635+
* Returns true while the workspace is in design mode (editor collapsed and
636+
* live preview expanded to fill the editor area).
637+
* @returns {boolean}
638+
*/
639+
function isInDesignMode() {
640+
return _isInDesignMode;
641+
}
642+
643+
/**
644+
* Sets the design-mode flag and fires EVENT_WORKSPACE_DESIGN_MODE_CHANGE when
645+
* the value actually changes. Intended to be called by the control bar; other
646+
* callers should use the dedicated toggle command instead.
647+
* @param {boolean} active
648+
*/
649+
function setDesignMode(active) {
650+
const next = !!active;
651+
if (_isInDesignMode === next) {
652+
return;
653+
}
654+
_isInDesignMode = next;
655+
exports.trigger(EVENT_WORKSPACE_DESIGN_MODE_CHANGE, _isInDesignMode);
656+
}
657+
622658
// Escape key and toggle panel special handling
623659
let _escapeKeyConsumers = {};
624660

@@ -776,6 +812,9 @@ define(function (require, exports, module) {
776812
exports.EVENT_WORKSPACE_UPDATE_LAYOUT = EVENT_WORKSPACE_UPDATE_LAYOUT;
777813
exports.EVENT_WORKSPACE_PANEL_SHOWN = EVENT_WORKSPACE_PANEL_SHOWN;
778814
exports.EVENT_WORKSPACE_PANEL_HIDDEN = EVENT_WORKSPACE_PANEL_HIDDEN;
815+
exports.EVENT_WORKSPACE_DESIGN_MODE_CHANGE = EVENT_WORKSPACE_DESIGN_MODE_CHANGE;
816+
exports.isInDesignMode = isInDesignMode;
817+
exports.setDesignMode = setDesignMode;
779818
exports.DEFAULT_PANEL_ID = DEFAULT_PANEL_ID;
780819

781820
/**

0 commit comments

Comments
 (0)