Skip to content

Commit 5faff3d

Browse files
committed
fix: live preview related css highlightfails due to space in path. detected by tests
1 parent 2ae3c55 commit 5faff3d

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/LiveDevelopment/MultiBrowserImpl/documents/LiveDocument.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ define(function (require, exports, module) {
3535
*/
3636
var SYNC_ERROR_CLASS = "live-preview-sync-error";
3737

38+
function _simpleHash(str) {
39+
let hash = 5381;
40+
for (let i = 0; i < str.length; ) {
41+
// eslint-disable-next-line no-bitwise
42+
hash = (hash * 33) ^ str.charCodeAt(i++);
43+
}
44+
// eslint-disable-next-line no-bitwise
45+
return hash >>> 0;
46+
}
47+
3848
/**
3949
* @constructor
4050
* Base class for managing the connection between a live editor and the browser. Provides functions
@@ -64,8 +74,9 @@ define(function (require, exports, module) {
6474
this._onActiveEditorChange = this._onActiveEditorChange.bind(this);
6575
this._onCursorActivity = this._onCursorActivity.bind(this);
6676

67-
EditorManager.off(`activeEditorChange.LiveDocument-${this.doc.file.fullPath}`);
68-
EditorManager.on(`activeEditorChange.LiveDocument-${this.doc.file.fullPath}`, this._onActiveEditorChange);
77+
this.fileHashForEvents = _simpleHash(this.doc.file.fullPath);
78+
EditorManager.off(`activeEditorChange.LiveDocument-${this.fileHashForEvents}`);
79+
EditorManager.on(`activeEditorChange.LiveDocument-${this.fileHashForEvents}`, this._onActiveEditorChange);
6980

7081
if (editor) {
7182
// Attach now
@@ -79,7 +90,7 @@ define(function (require, exports, module) {
7990
* Closes the live document, terminating its connection to the browser.
8091
*/
8192
LiveDocument.prototype.close = function () {
82-
EditorManager.off(`activeEditorChange.LiveDocument-${this.doc.file.fullPath}`);
93+
EditorManager.off(`activeEditorChange.LiveDocument-${this.fileHashForEvents}`);
8394
this._clearErrorDisplay();
8495
this._detachFromEditor();
8596
};

src/LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ define(function (require, exports, module) {
275275
function _send(msg, clients) {
276276
var id = _nextMsgId++,
277277
result = new $.Deferred();
278+
if(!_transport){
279+
console.error("Cannot send message before live preview transport initialised");
280+
result.reject();
281+
return result.promise();
282+
}
278283

279284
// broadcast if there are no specific clients
280285
clients = clients || getConnectionIds();

0 commit comments

Comments
 (0)