@@ -32,6 +32,7 @@ define(function (require, exports, module) {
3232 FileSystem = require ( "filesystem/FileSystem" ) ,
3333 FileUtils = require ( "file/FileUtils" ) ,
3434 EditorManager = require ( "editor/EditorManager" ) ,
35+ DocumentManager = require ( "document/DocumentManager" ) ,
3536 ExtensionUtils = require ( "utils/ExtensionUtils" ) ,
3637 ThemeSettings = require ( "view/ThemeSettings" ) ,
3738 ThemeView = require ( "view/ThemeView" ) ,
@@ -193,6 +194,19 @@ define(function (require, exports, module) {
193194 }
194195
195196
197+ let currentTrackingDoc ;
198+ function _trackLivePreviewDevThemeFile ( themeFilePath , devTheme ) {
199+ DocumentManager . getDocumentForPath ( themeFilePath ) . done ( doc => {
200+ if ( currentTrackingDoc ) {
201+ currentTrackingDoc . off ( "change.ThemeManager" ) ;
202+ }
203+ currentTrackingDoc = doc ;
204+ doc . on ( "change.ThemeManager" , ( ) => {
205+ _applyThemeCSS ( doc . getText ( ) , devTheme ) ;
206+ } ) ;
207+ } ) . fail ( console . error ) ;
208+ }
209+
196210 /**
197211 * Extension developers can load their custom themes using debug menu> load project as extension. in this case
198212 * a query strin param will ge specified with the dev extension path. we will always load that theme as default
@@ -231,12 +245,18 @@ define(function (require, exports, module) {
231245 // check if a dev theme is loaded via query string parameter. If so that will be the current theme.
232246 let devTheme = _getCurrentlyLoadedDevTheme ( ) ;
233247 if ( devTheme ) {
234- return devTheme ;
235- }
236- if ( ! currentTheme ) {
248+ currentTheme = devTheme ;
249+ } else if ( ! currentTheme ) {
237250 currentTheme = loadedThemes [ prefs . get ( "theme" ) ] || loadedThemes [ defaultTheme ] ;
238251 }
239252
253+ if ( currentTheme ) {
254+ _trackLivePreviewDevThemeFile ( currentTheme . file . fullPath , currentTheme ) ;
255+ EditorManager . off ( EditorManager . EVENT_ACTIVE_EDITOR_CHANGED + ".ThemeManager" ) ;
256+ EditorManager . on ( EditorManager . EVENT_ACTIVE_EDITOR_CHANGED + ".ThemeManager" , ( ) => {
257+ _trackLivePreviewDevThemeFile ( currentTheme . file . fullPath , currentTheme ) ;
258+ } ) ;
259+ }
240260 return currentTheme ;
241261 }
242262
0 commit comments