@@ -151,9 +151,14 @@ define(function LiveDevelopment(require, exports, module) {
151151
152152 var _liveDocument ; // the document open for live editing.
153153 var _relatedDocuments ; // CSS and JS documents that are used by the live HTML document
154- var _server ; // current live dev server
155154 var _openDeferred ; // promise returned for each call to open()
156155
156+ /**
157+ * Current live preview server
158+ * @type {BaseServer }
159+ */
160+ var _server ;
161+
157162 function _isHtmlFileExt ( ext ) {
158163 return ( FileUtils . isStaticHtmlFileExt ( ext ) ||
159164 ( ProjectManager . getBaseUrl ( ) && FileUtils . isServerHtmlFileExt ( ext ) ) ) ;
@@ -185,23 +190,11 @@ define(function LiveDevelopment(require, exports, module) {
185190 }
186191
187192 function getLiveDocForPath ( path ) {
188- var docsToSearch = [ ] ;
189- if ( _relatedDocuments ) {
190- docsToSearch = docsToSearch . concat ( _relatedDocuments ) ;
191- }
192- if ( _liveDocument ) {
193- docsToSearch = docsToSearch . concat ( _liveDocument ) ;
193+ if ( ! _server ) {
194+ return undefined ;
194195 }
195- var foundDoc ;
196- docsToSearch . some ( function matchesPath ( ele ) {
197- if ( ele . doc . file . fullPath === path ) {
198- foundDoc = ele ;
199- return true ;
200- }
201- return false ;
202- } ) ;
203-
204- return foundDoc ;
196+
197+ return _server . get ( path ) ;
205198 }
206199
207200 function getLiveDocForEditor ( editor ) {
@@ -1106,10 +1099,29 @@ define(function LiveDevelopment(require, exports, module) {
11061099 }
11071100 }
11081101
1109- /** Triggered by a document saved from the DocumentManager */
1102+ /**
1103+ * Triggered by a documentSaved event from DocumentManager.
1104+ * @param {$.Event } event
1105+ * @param {Document } doc
1106+ */
11101107 function _onDocumentSaved ( event , doc ) {
1111- if ( doc && Inspector . connected ( ) && _classForDocument ( doc ) !== CSSDocument &&
1112- agents . network && agents . network . wasURLRequested ( doc . url ) ) {
1108+ if ( ! Inspector . connected ( ) || ! _server ) {
1109+ return ;
1110+ }
1111+
1112+ var absolutePath = doc . file . fullPath ,
1113+ liveDocument = absolutePath && _server . get ( absolutePath ) ,
1114+ liveEditingEnabled = liveDocument && liveDocument . isLiveEditingEnabled && liveDocument . isLiveEditingEnabled ( ) ;
1115+
1116+ // Skip reload if the saved document has live editing enabled
1117+ if ( liveEditingEnabled ) {
1118+ return ;
1119+ }
1120+
1121+ var documentUrl = _server . pathToUrl ( absolutePath ) ,
1122+ wasRequested = agents . network && agents . network . wasURLRequested ( documentUrl ) ;
1123+
1124+ if ( wasRequested ) {
11131125 // Unload and reload agents before reloading the page
11141126 reconnect ( ) ;
11151127
0 commit comments