Skip to content

Commit 330640e

Browse files
committed
fix: live preview UX where clicking on lp will open html when editing unrelated ts/json/js file
1 parent 5604c38 commit 330640e

File tree

2 files changed

+5
-47
lines changed

2 files changed

+5
-47
lines changed

src/LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ define(function (require, exports, module) {
163163
activeEditor && activeEditor.focus(); // restore focus from live preview
164164
return;
165165
}
166-
const openFullEditors = MainViewManager.findInOpenPane(liveDocPath);
167-
const openLiveDocEditor = openFullEditors.length ? openFullEditors[0].editor : null;
166+
const allOpenFileCount = MainViewManager.getWorkingSetSize(MainViewManager.ALL_PANES);
168167
function selectInHTMLEditor(fullHtmlEditor) {
169168
const position = HTMLInstrumentation.getPositionFromTagId(fullHtmlEditor, parseInt(tagId, 10));
170169
if(position && fullHtmlEditor) {
@@ -183,19 +182,10 @@ define(function (require, exports, module) {
183182
_focusEditorIfNeeded(activeEditor, nodeName, contentEditable);
184183
_searchAndCursorIfCSS(activeEditor, allSelectors, nodeName);
185184
// in this case, see if we need to do any css reverse highlight magic here
186-
} else if(openLiveDocEditor) {
187-
// If we are on multi pane mode, the html doc was open in an inactive unfocused editor.
188-
selectInHTMLEditor(openLiveDocEditor);
189-
} else {
190-
// no open editor for the live doc in panes, check if there is one in the working set.
191-
const foundInWorkingSetPane = MainViewManager.findInAllWorkingSets(liveDocPath);
192-
const paneToUse = foundInWorkingSetPane.length ?
193-
foundInWorkingSetPane[0].paneId:
194-
MainViewManager.ACTIVE_PANE; // if pane id is active pane, then the file is not open in working set
195-
const viewToUse = (paneToUse === MainViewManager.ACTIVE_PANE) ?
196-
FileViewController.PROJECT_MANAGER:
197-
FileViewController.WORKING_SET_VIEW;
198-
FileViewController.openAndSelectDocument(liveDocPath, viewToUse, paneToUse)
185+
} else if(!allOpenFileCount){
186+
// no open editor in any panes, then open the html file directly.
187+
FileViewController.openAndSelectDocument(liveDocPath,
188+
FileViewController.WORKING_SET_VIEW, MainViewManager.ACTIVE_PANE)
199189
.done(()=>{
200190
selectInHTMLEditor(EditorManager.getActiveEditor());
201191
});

test/spec/LiveDevelopmentMultiBrowser-test.js

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,38 +1431,6 @@ define(function (require, exports, module) {
14311431
await endPreviewSession();
14321432
}, 30000);
14331433

1434-
it("should open html in correct pane on clicking live preview in split pane", async function () {
1435-
MainViewManager.setLayoutScheme(1, 2);
1436-
MainViewManager.setActivePaneId(MainViewManager.FIRST_PANE);
1437-
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["cssLivePreview.html"], MainViewManager.FIRST_PANE),
1438-
"SpecRunnerUtils.openProjectFiles cssLivePreview.html");
1439-
1440-
await waitsForLiveDevelopmentToOpen();
1441-
1442-
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["simple1.css"], MainViewManager.SECOND_PANE),
1443-
"SpecRunnerUtils.openProjectFiles simple1.css"); // non related file
1444-
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["blank.css"], MainViewManager.FIRST_PANE),
1445-
"SpecRunnerUtils.openProjectFiles blank.css"); // non related file
1446-
1447-
// now the live preview page's editor is not visible in any panes, but is already open in first pane
1448-
// so, on clicking live preview, it should open the file in first pane
1449-
MainViewManager.setActivePaneId(MainViewManager.SECOND_PANE);
1450-
1451-
await forRemoteExec(`document.getElementById("testId2").click()`);
1452-
let editor = EditorManager.getActiveEditor();
1453-
await awaitsFor(()=>{
1454-
editor = EditorManager.getActiveEditor();
1455-
return editor && editor.document.file.name === "cssLivePreview.html";
1456-
}, "cssLivePreview.html to open as active editor");
1457-
await _forSelection("#testId", editor, { line: 13, ch: 4, sticky: null });
1458-
editor = EditorManager.getActiveEditor();
1459-
expect(editor.document.file.name).toBe("cssLivePreview.html");
1460-
expect(MainViewManager.getActivePaneId()).toBe(MainViewManager.FIRST_PANE);
1461-
1462-
MainViewManager.setLayoutScheme(1, 1);
1463-
await endPreviewSession();
1464-
}, 30000);
1465-
14661434
it("should reverse highlight open previewed html file if not open on clicking live preview", async function () {
14671435
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["simple1.html"]),
14681436
"SpecRunnerUtils.openProjectFiles simple1.html");

0 commit comments

Comments
 (0)