Skip to content

Commit 8fda875

Browse files
committed
deploy: 851cfff
1 parent d9056c7 commit 8fda875

File tree

38 files changed

+247
-3119
lines changed

38 files changed

+247
-3119
lines changed

LiveDevelopment/LiveDevMultiBrowser.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ define(function (require, exports, module) {
5858

5959

6060
// Status Codes
61-
var STATUS_INACTIVE = exports.STATUS_INACTIVE = 0;
62-
var STATUS_CONNECTING = exports.STATUS_CONNECTING = 1;
63-
var STATUS_ACTIVE = exports.STATUS_ACTIVE = 2;
64-
var STATUS_OUT_OF_SYNC = exports.STATUS_OUT_OF_SYNC = 3;
65-
var STATUS_SYNC_ERROR = exports.STATUS_SYNC_ERROR = 4;
66-
var STATUS_RELOADING = exports.STATUS_RELOADING = 5;
67-
var STATUS_RESTARTING = exports.STATUS_RESTARTING = 6;
68-
69-
var CommandManager = require("command/CommandManager"),
61+
const STATUS_INACTIVE = exports.STATUS_INACTIVE = 0;
62+
const STATUS_CONNECTING = exports.STATUS_CONNECTING = 1;
63+
const STATUS_ACTIVE = exports.STATUS_ACTIVE = 2;
64+
const STATUS_OUT_OF_SYNC = exports.STATUS_OUT_OF_SYNC = 3;
65+
const STATUS_SYNC_ERROR = exports.STATUS_SYNC_ERROR = 4;
66+
const STATUS_RELOADING = exports.STATUS_RELOADING = 5;
67+
const STATUS_RESTARTING = exports.STATUS_RESTARTING = 6;
68+
69+
const CommandManager = require("command/CommandManager"),
7070
Commands = require("command/Commands"),
7171
Dialogs = require("widgets/Dialogs"),
7272
DefaultDialogs = require("widgets/DefaultDialogs"),
@@ -86,7 +86,7 @@ define(function (require, exports, module) {
8686
DefaultLauncher = require("LiveDevelopment/MultiBrowserImpl/launchers/Launcher");
8787

8888
// Documents
89-
var LiveCSSDocument = require("LiveDevelopment/MultiBrowserImpl/documents/LiveCSSDocument"),
89+
const LiveCSSDocument = require("LiveDevelopment/MultiBrowserImpl/documents/LiveCSSDocument"),
9090
LiveHTMLDocument = require("LiveDevelopment/MultiBrowserImpl/documents/LiveHTMLDocument");
9191

9292
/**
@@ -96,6 +96,12 @@ define(function (require, exports, module) {
9696
*/
9797
var _liveDocument;
9898

99+
/**
100+
* Live preview only tracks the pinned document.
101+
* @type {boolean}
102+
*/
103+
let livePreviewUrlPinned = false;
104+
99105
/**
100106
* @private
101107
* Live documents related to the active HTML document - for example, CSS files
@@ -652,7 +658,7 @@ define(function (require, exports, module) {
652658
*/
653659
function _onFileChange() {
654660
var doc = DocumentManager.getCurrentDocument();
655-
if (!isActive() || !doc) {
661+
if (!isActive() || !doc || livePreviewUrlPinned) {
656662
return;
657663
}
658664

@@ -875,6 +881,13 @@ define(function (require, exports, module) {
875881
}
876882
}
877883

884+
/**
885+
* @param urlPinned {boolean}
886+
*/
887+
function setLivePreviewPinned(urlPinned) {
888+
livePreviewUrlPinned = urlPinned;
889+
}
890+
878891
/**
879892
* Returns current project server config. Copied from original LiveDevelopment.
880893
*/
@@ -897,15 +910,14 @@ define(function (require, exports, module) {
897910
}
898911

899912
// for unit testing only
900-
function _getCurrentLiveDoc() {
913+
function getCurrentLiveDoc() {
901914
return _liveDocument;
902915
}
903916

904917
EventDispatcher.makeEventDispatcher(exports);
905918

906919
// For unit testing
907920
exports._server = _server;
908-
exports._getCurrentLiveDoc = _getCurrentLiveDoc;
909921
exports._getInitialDocFromCurrent = _getInitialDocFromCurrent;
910922

911923
// Export public functions
@@ -919,7 +931,9 @@ define(function (require, exports, module) {
919931
exports.redrawHighlight = redrawHighlight;
920932
exports.init = init;
921933
exports.isActive = isActive;
934+
exports.setLivePreviewPinned= setLivePreviewPinned;
922935
exports.getServerBaseUrl = getServerBaseUrl;
936+
exports.getCurrentLiveDoc = getCurrentLiveDoc;
923937
exports.getCurrentProjectServerConfig = getCurrentProjectServerConfig;
924938
exports.setTransport = setTransport;
925939
exports.setLauncher = setLauncher;

LiveDevelopment/MultiBrowserImpl/documents/LiveDocument.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ define(function (require, exports, module) {
151151
// Temporarily disabling this code to make JS editing work.
152152
// this._detachFromEditor();
153153

154-
if (newActive && newActive.document === this.doc) {
154+
if (newActive && newActive.document.file.fullPath === this.doc.file.fullPath) {
155155
this._attachToEditor(newActive);
156156
}
157157
};
@@ -165,6 +165,7 @@ define(function (require, exports, module) {
165165
this.editor = editor;
166166

167167
if (this.editor) {
168+
this.setInstrumentationEnabled(true, true);
168169
this.editor.on("cursorActivity", this._onCursorActivity);
169170
this.updateHighlight();
170171
}

LiveDevelopment/MultiBrowserImpl/documents/LiveHTMLDocument.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ define(function (require, exports, module) {
4949
*/
5050
function LiveHTMLDocument(protocol, urlResolver, doc, editor) {
5151
LiveDocument.apply(this, arguments);
52+
this.doc.addRef();
5253

5354
this._instrumentationEnabled = false;
5455
this._relatedDocuments = {
@@ -98,13 +99,14 @@ define(function (require, exports, module) {
9899
* TODO: this doesn't seem necessary...if we're a live document, we should
99100
* always have instrumentation on anyway.
100101
* @param {boolean} enabled
102+
* @param {boolean} [force]
101103
*/
102-
LiveHTMLDocument.prototype.setInstrumentationEnabled = function (enabled) {
104+
LiveHTMLDocument.prototype.setInstrumentationEnabled = function (enabled, force) {
103105
if (!this.editor) {
104106
// TODO: error
105107
return;
106108
}
107-
if (enabled && !this._instrumentationEnabled) {
109+
if (enabled && (force || !this._instrumentationEnabled)) {
108110
// TODO: not clear why we do this here instead of waiting for the next time we want to
109111
// generate the instrumented HTML. This won't work if the dom offsets are out of date.
110112
HTMLInstrumentation.scanDocument(this.doc);
@@ -134,6 +136,7 @@ define(function (require, exports, module) {
134136
* Closes the live document, terminating its connection to the browser.
135137
*/
136138
LiveHTMLDocument.prototype.close = function () {
139+
this.doc.releaseRef();
137140
this.doc.off("change", this._onChange);
138141
this.protocol.off("DocumentRelated", this._onRelated);
139142
this.protocol.off("StylesheetAdded", this._onStylesheetAdded);

LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ define(function (require, exports, module) {
5151

5252
var DocumentManager = require("document/DocumentManager"),
5353
HTMLDOMDiff = require("language/HTMLDOMDiff"),
54-
HTMLSimpleDOM = require("LiveDevelopment/MultiBrowserImpl/language/HTMLSimpleDOM");
54+
HTMLSimpleDOM = require("LiveDevelopment/MultiBrowserImpl/language/HTMLSimpleDOM"),
55+
_ = require("thirdparty/lodash");
5556

5657
var allowIncremental = true;
5758

@@ -842,6 +843,20 @@ define(function (require, exports, module) {
842843
_cachedValues = {};
843844
}
844845

846+
function getPositionFromTagId(editor, tagId) {
847+
var marks = editor._codeMirror.getAllMarks(),
848+
markFound;
849+
850+
markFound = _.find(marks, function (mark) {
851+
return (mark.tagID === tagId);
852+
});
853+
if (markFound) {
854+
return markFound.find().from;
855+
}
856+
return null;
857+
858+
}
859+
845860
// private methods
846861
exports._markText = _markText;
847862
exports._getMarkerAtDocumentPos = _getMarkerAtDocumentPos;
@@ -851,6 +866,7 @@ define(function (require, exports, module) {
851866
exports._allowIncremental = allowIncremental;
852867
exports._getBrowserDiff = _getBrowserDiff;
853868
exports._resetCache = _resetCache;
869+
exports.getPositionFromTagId = getPositionFromTagId;
854870

855871
// public API
856872
exports.scanDocument = scanDocument;

LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ define(function (require, exports, module) {
4747
RemoteFunctions = require("text!LiveDevelopment/BrowserScripts/RemoteFunctions.js"),
4848
EditorManager = require("editor/EditorManager"),
4949
LiveDevMultiBrowser = require("LiveDevelopment/LiveDevMultiBrowser"),
50-
HTMLInstrumentation = require("language/HTMLInstrumentation");
50+
HTMLInstrumentation = require("LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation"),
51+
FileViewController = require("project/FileViewController");
5152

5253
/**
5354
* @private
@@ -111,10 +112,24 @@ define(function (require, exports, module) {
111112
}
112113
}
113114
} else if (msg.tagId) {
114-
var editor = EditorManager.getActiveEditor(),
115-
position = HTMLInstrumentation.getPositionFromTagId(editor, parseInt(msg.tagId, 10));
116-
if (position) {
117-
editor.setCursorPos(position.line, position.ch, true);
115+
const liveDoc = LiveDevMultiBrowser.getCurrentLiveDoc(),
116+
editor = EditorManager.getActiveEditor();
117+
const liveDocPath = liveDoc ? liveDoc.doc.file.fullPath : null,
118+
activeEditorDocPath = editor ? editor.document.file.fullPath : null;
119+
function selectInActiveDocument() {
120+
const activeFullEditor = EditorManager.getCurrentFullEditor();
121+
const masterEditor = activeFullEditor && activeFullEditor.document._masterEditor?
122+
activeFullEditor.document._masterEditor : activeFullEditor;
123+
const position = HTMLInstrumentation.getPositionFromTagId(masterEditor, parseInt(msg.tagId, 10));
124+
if (position) {
125+
activeFullEditor.setCursorPos(position.line, position.ch, true);
126+
}
127+
}
128+
if(liveDocPath !== activeEditorDocPath) {
129+
FileViewController.openAndSelectDocument(liveDocPath, FileViewController.PROJECT_MANAGER)
130+
.done(selectInActiveDocument);
131+
} else {
132+
selectInActiveDocument();
118133
}
119134
} else {
120135
// enrich received message with clientId

LiveDevelopment/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ define(function main(require, exports, module) {
138138
}
139139
}
140140

141+
function setLivePreviewPinned(urlPinned) {
142+
LiveDevImpl.setLivePreviewPinned(urlPinned);
143+
}
144+
141145
/** Called on status change */
142146
function _showStatusChangeReason(reason) {
143147
// Destroy the previous twipsy (options are not updated otherwise)
@@ -285,4 +289,5 @@ define(function main(require, exports, module) {
285289
// Export public functions
286290
exports.openLivePreview = openLivePreview;
287291
exports.closeLivePreview = closeLivePreview;
292+
exports.setLivePreviewPinned = setLivePreviewPinned;
288293
});

assets/default-project/en.zip

0 Bytes
Binary file not shown.

assets/sample-projects/HTML5.zip

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)