Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #8844 from adobe/rlim/parse-less-and-scss
Browse files Browse the repository at this point in the history
Changes for all the late feedback of pull request 8720.
  • Loading branch information
redmunds committed Aug 26, 2014
2 parents 08ecc8f + 03d8cfa commit 733a07d
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 83 deletions.
75 changes: 39 additions & 36 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,34 @@ define(function LiveDevelopment(require, exports, module) {
return result.promise();
}

/**
* If the current editor is for a CSS preprocessor file, then add it to the style sheet
* so that we can track cursor positions in the editor to show live preview highlighting.
* For normal CSS we only do highlighting from files we know for sure are referenced by the
* current live preview document, but for preprocessors we just assume that any preprocessor
* file you edit is probably related to the live preview.
*
* @param {Event} event (unused)
* @param {Editor} current Current editor
* @param {Editor} previous Previous editor
*
*/
function onActiveEditorChange(event, current, previous) {
if (previous && previous.document &&
FileUtils.isCSSPreprocessorFile(previous.document.file.fullPath)) {
var prevDocUrl = _server && _server.pathToUrl(previous.document.file.fullPath);

if (_relatedDocuments && _relatedDocuments[prevDocUrl]) {
_closeRelatedDocument(_relatedDocuments[prevDocUrl]);
}
}
if (current && current.document &&
FileUtils.isCSSPreprocessorFile(current.document.file.fullPath)) {
var docUrl = _server && _server.pathToUrl(current.document.file.fullPath);
_styleSheetAdded(null, docUrl);
}
}

/**
* @private
* While still connected to the Inspector, do cleanup for agents,
Expand All @@ -768,6 +796,8 @@ define(function LiveDevelopment(require, exports, module) {
deferred = new $.Deferred(),
connected = Inspector.connected();

$(EditorManager).off("activeEditorChange", onActiveEditorChange);

$(Inspector.Page).off(".livedev");
$(Inspector).off(".livedev");

Expand Down Expand Up @@ -1209,6 +1239,15 @@ define(function LiveDevelopment(require, exports, module) {

// open browser to the interstitial page to prepare for loading agents
_openInterstitialPage();

// Setup activeEditorChange event listener so that we can track cursor positions in
// CSS preprocessor files and perform live preview highlighting on all elements with
// the current selector in the preprocessor file.
$(EditorManager).on("activeEditorChange", onActiveEditorChange);

// Explicitly trigger onActiveEditorChange so that live preview highlighting
// can be set up for the preprocessor files.
onActiveEditorChange(null, EditorManager.getActiveEditor(), null);
}

function _prepareServer(doc) {
Expand Down Expand Up @@ -1253,34 +1292,6 @@ define(function LiveDevelopment(require, exports, module) {
return deferred.promise();
}

/**
* If the current editor is for a preprocessor file, then add it to the style sheet
* so that we can track cursor positions in the editor to show live preview highlighting.
* For normal CSS we only do highlighting from files we know for sure are referenced by the
* current live preview document, but for preprocessors we just assume that any preprocessor
* file you edit is probably related to the live preview.
*
* @param {Event} event (unused)
* @param {Editor} current Current editor
* @param {Editor} previous Previous editor
*
*/
function onActiveEditorChange(event, current, previous) {
if (previous && previous.document &&
FileUtils.isCSSPreprocessorFile(previous.document.file.fullPath)) {
var prevDocUrl = _server && _server.pathToUrl(previous.document.file.fullPath);

if (_relatedDocuments && _relatedDocuments[prevDocUrl]) {
_closeRelatedDocument(_relatedDocuments[prevDocUrl]);
}
}
if (current && current.document &&
FileUtils.isCSSPreprocessorFile(current.document.file.fullPath)) {
var docUrl = _server && _server.pathToUrl(current.document.file.fullPath);
_styleSheetAdded(null, docUrl);
}
}

/**
* Open the Connection and go live
*
Expand Down Expand Up @@ -1326,10 +1337,6 @@ define(function LiveDevelopment(require, exports, module) {
prepareServerPromise
.done(function () {
_doLaunchAfterServerReady(doc);

// Explicitly trigger onActiveEditorChange so that live preview highlighting
// can be set up for the preprocessor files.
onActiveEditorChange(null, EditorManager.getActiveEditor(), null);
})
.fail(function () {
_showWrongDocError();
Expand Down Expand Up @@ -1486,10 +1493,6 @@ define(function LiveDevelopment(require, exports, module) {
return _server && _server.getBaseUrl();
}

// Setup activeEditorChange event listener so that we can track cursor positions in
// preprocessor files and perform live preview highlighting on all elements with
// the current selector in the preprocessor file.
$(EditorManager).on("activeEditorChange", onActiveEditorChange);


// For unit testing
Expand Down
7 changes: 4 additions & 3 deletions src/file/FileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,13 @@ define(function (require, exports, module) {
}

/**
* Determine if file extension is a CSS preprocessor file extension that Brackets supports.
* Determines if file extension is a CSS preprocessor file extension that Brackets supports.
* @param {string} filePath could be a path, a file name
* @return {boolean} Returns true if file extension is either less or scss.
* @return {boolean} true if LanguageManager identifies filePath as less or scss language.
*/
function isCSSPreprocessorFile(filePath) {
return (/(less|scss)/i.test(getFileExtension(filePath)));
var languageId = LanguageManager.getLanguageForPath(filePath).getId();
return (languageId === "less" || languageId === "scss");
}

/**
Expand Down
Loading

0 comments on commit 733a07d

Please sign in to comment.