Skip to content

Commit 80bd954

Browse files
committed
fix(live-preview): don't steal editor focus on iframe click in design mode
In design mode the editor area is collapsed, so pulling focus into it when the user clicks/Escapes inside the live preview or markdown viewer iframe is disorienting. Gate all such focus-shift paths on WorkspaceManager.isInDesignMode(): - _focusEditorIfNeeded and the no-liveDoc fallback in LiveDevProtocol (HTML live preview edit/highlight click flow) - focusActiveEditorIfFocusInLivePreview helper (md viewer preview-mode click, md viewer Escape, HTML iframe Escape) Cursor positioning is preserved so the cursor still lands correctly if the user later switches out of design mode.
1 parent 11b99a0 commit 80bd954

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ define(function (require, exports, module) {
5353
HTMLInstrumentation = require("LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation"),
5454
StringUtils = require("utils/StringUtils"),
5555
FileViewController = require("project/FileViewController"),
56-
MainViewManager = require("view/MainViewManager");
56+
MainViewManager = require("view/MainViewManager"),
57+
WorkspaceManager = require("view/WorkspaceManager");
5758

5859
const LIVE_DEV_REMOTE_SCRIPTS_FILE_NAME = `phoenix_live_preview_scripts_instrumented_${StringUtils.randomString(8)}.js`;
5960
const LIVE_DEV_REMOTE_WORKER_SCRIPTS_FILE_NAME = `pageLoaderWorker_${StringUtils.randomString(8)}.js`;
@@ -189,6 +190,9 @@ define(function (require, exports, module) {
189190
* @private
190191
*/
191192
function _focusEditorIfNeeded(editor, tagName, contentEditable) {
193+
if (WorkspaceManager.isInDesignMode()) {
194+
return;
195+
}
192196
const focusShouldBeInLivePreview = ['INPUT', 'TEXTAREA'].includes(tagName) || contentEditable;
193197
if(focusShouldBeInLivePreview){
194198
return;
@@ -247,7 +251,9 @@ define(function (require, exports, module) {
247251
activeEditorPath = activeEditor ? activeEditor.document.file.fullPath : null,
248252
activeFullEditorPath = activeFullEditor ? activeFullEditor.document.file.fullPath : null;
249253
if(!liveDocPath){
250-
activeEditor && activeEditor.focus(); // restore focus from live preview
254+
if (activeEditor && !WorkspaceManager.isInDesignMode()) {
255+
activeEditor.focus(); // restore focus from live preview
256+
}
251257
return;
252258
}
253259
const allOpenFileCount = MainViewManager.getWorkingSetSize(MainViewManager.ALL_PANES);

src/extensionsIntegrated/Phoenix-live-preview/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,16 @@ define(function (require, exports, module) {
3939
const LIVE_PREVIEW_IFRAME_ID = "panel-live-preview-frame";
4040
const MDVIEWR_IFRAME_ID = "panel-md-preview-frame";
4141
const EditorManager = require("editor/EditorManager");
42+
const WorkspaceManager = require("view/WorkspaceManager");
4243
// File-type classification helpers live in a shared utility module so
4344
// non-live-preview code (e.g. Quick Open in design mode) can use them
4445
// without depending on this extension.
4546
const FileTypeUtils = require("utils/FileTypeUtils");
4647

4748
function focusActiveEditorIfFocusInLivePreview() {
49+
if (WorkspaceManager.isInDesignMode()) {
50+
return;
51+
}
4852
const editor = EditorManager.getActiveEditor();
4953
if(!editor){
5054
return;

0 commit comments

Comments
 (0)