diff --git a/src/editor/EditorCommandHandlers.js b/src/editor/EditorCommandHandlers.js index df76575eb6..7a8aa3669d 100644 --- a/src/editor/EditorCommandHandlers.js +++ b/src/editor/EditorCommandHandlers.js @@ -33,6 +33,7 @@ define(function (require, exports, module) { Editor = require("editor/Editor").Editor, CommandManager = require("command/CommandManager"), EditorManager = require("editor/EditorManager"), + WorkspaceManager = require("view/WorkspaceManager"), StringUtils = require("utils/StringUtils"), TokenUtils = require("utils/TokenUtils"), CodeMirror = require("thirdparty/CodeMirror/lib/codemirror"), @@ -1185,6 +1186,16 @@ define(function (require, exports, module) { var editor = EditorManager.getFocusedEditor(); var result = new $.Deferred(); + // In design mode the active document often lives behind an external + // surface that owns DOM focus (e.g. the markdown viewer iframe in + // edit mode), so getFocusedEditor() returns null even though there + // is an underlying Phoenix editor whose doc captures the changes. + // Fall back to the active-pane full editor so toolbar undo/redo + // still drives the document's history in that state. + if (!editor && WorkspaceManager.isInDesignMode()) { + editor = EditorManager.getCurrentFullEditor(); + } + if (editor) { editor[operation](); result.resolve(); diff --git a/src/extensionsIntegrated/Phoenix-live-preview/main.js b/src/extensionsIntegrated/Phoenix-live-preview/main.js index dedef328dd..e83743ea01 100644 --- a/src/extensionsIntegrated/Phoenix-live-preview/main.js +++ b/src/extensionsIntegrated/Phoenix-live-preview/main.js @@ -369,8 +369,10 @@ define(function (require, exports, module) { function _initializeMode() { const currentMode = LiveDevelopment.getCurrentMode(); - // when in preview mode, we need to give the play button a selected state - if (currentMode === LiveDevelopment.CONSTANTS.LIVE_PREVIEW_MODE) { + // Pencil button lights up only when edit mode is active; preview / + // highlight modes leave it un-tinted. Click toggles between edit + // and preview. + if (currentMode === LiveDevelopment.CONSTANTS.LIVE_EDIT_MODE) { $previewBtn.addClass('selected'); } else { $previewBtn.removeClass('selected'); @@ -744,19 +746,29 @@ define(function (require, exports, module) { } /** - * Handle preview button click - toggles between preview mode and the user's default mode. - * PRO users toggle between preview and edit mode. - * community users toggle between preview and highlight mode. + * Toggles between edit mode and preview mode. The pencil button lights up + * (via .selected applied in _initializeMode) when edit mode is active; + * clicking it when already in edit drops back to preview. Clicking when + * NOT in edit tries to enter edit through LiveDevelopment.setMode, which + * returns false for users without the live-edit entitlement — in that + * case we show the same pro upsell dialog the mode dropdown uses, + * mirroring its "Edit Mode" item. _initializeMode reconciles the + * .selected class against the actual current mode after the pref + * change lands. */ function _handlePreviewBtnClick() { - if($previewBtn.hasClass('selected')) { - $previewBtn.removeClass('selected'); - const defaultMode = isProEditUser ? 'edit' : 'highlight'; - PreferencesManager.set(PREFERENCE_LIVE_PREVIEW_MODE, defaultMode); - } else { - // Currently NOT in preview mode - switch to preview - $previewBtn.addClass('selected'); - PreferencesManager.set(PREFERENCE_LIVE_PREVIEW_MODE, "preview"); + const currentMode = LiveDevelopment.getCurrentMode(); + if (currentMode === LiveDevelopment.CONSTANTS.LIVE_EDIT_MODE) { + LiveDevelopment.setMode(LiveDevelopment.CONSTANTS.LIVE_PREVIEW_MODE); + return; + } + if (!LiveDevelopment.setMode(LiveDevelopment.CONSTANTS.LIVE_EDIT_MODE)) { + if (KernalModeTrust.ProDialogs) { + KernalModeTrust.ProDialogs.showProUpsellDialog( + KernalModeTrust.ProDialogs.UPSELL_TYPE_LIVE_EDIT); + } else { + Metrics.countEvent(Metrics.EVENT_TYPE.PRO, "proUpsellDlg", "fail"); + } } } @@ -765,7 +777,7 @@ define(function (require, exports, module) { Strings: Strings, livePreview: Strings.LIVE_DEV_STATUS_TIP_OUT_OF_SYNC, clickToReload: Strings.LIVE_DEV_CLICK_TO_RELOAD_PAGE, - clickToPreview: Strings.LIVE_PREVIEW_MODE_TOGGLE_PREVIEW, + clickToToggleEdit: Strings.LIVE_PREVIEW_MODE_TOGGLE_EDIT, switchToDesignMode: Strings.CCB_SWITCH_TO_DESIGN_MODE, livePreviewSettings: Strings.LIVE_DEV_SETTINGS, livePreviewConfigureModes: Strings.LIVE_PREVIEW_CONFIGURE_MODES, diff --git a/src/extensionsIntegrated/Phoenix-live-preview/panel.html b/src/extensionsIntegrated/Phoenix-live-preview/panel.html index d5fd35a6fe..d62408e8f7 100644 --- a/src/extensionsIntegrated/Phoenix-live-preview/panel.html +++ b/src/extensionsIntegrated/Phoenix-live-preview/panel.html @@ -7,8 +7,8 @@ - diff --git a/src/index.html b/src/index.html index f44dc52308..04627123b5 100644 --- a/src/index.html +++ b/src/index.html @@ -969,6 +969,13 @@ +
+
+
+ + +
+