11define ( function ( require , exports , module ) {
2- const EditorManager = require ( "editor/EditorManager" ) ;
32 const HTMLInstrumentation = require ( "LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation" ) ;
3+ const LiveDevMultiBrowser = require ( "LiveDevelopment/LiveDevMultiBrowser" ) ;
44
55 /**
66 * this function handles the text edit in the source code when user updates the text in the live preview
@@ -18,7 +18,13 @@ define(function (require, exports, module) {
1818 * join the text back and add the new content in between
1919 */
2020 function _editTextInSource ( message ) {
21- const editor = EditorManager . getActiveEditor ( ) ;
21+ // this is to get the currently live document that is being served in the live preview
22+ const currLiveDoc = LiveDevMultiBrowser . getCurrentLiveDoc ( ) ;
23+ if ( ! currLiveDoc ) {
24+ return ;
25+ }
26+
27+ const editor = currLiveDoc . editor ;
2228 if ( ! editor || ! message . tagId ) {
2329 return ;
2430 }
@@ -54,7 +60,13 @@ define(function (require, exports, module) {
5460 * @param {Number } tagId - the data-brackets-id of the DOM element
5561 */
5662 function _duplicateElementInSourceByTagId ( tagId ) {
57- const editor = EditorManager . getActiveEditor ( ) ;
63+ // this is to get the currently live document that is being served in the live preview
64+ const currLiveDoc = LiveDevMultiBrowser . getCurrentLiveDoc ( ) ;
65+ if ( ! currLiveDoc ) {
66+ return ;
67+ }
68+
69+ const editor = currLiveDoc . editor ;
5870 if ( ! editor || ! tagId ) {
5971 return ;
6072 }
@@ -96,7 +108,13 @@ define(function (require, exports, module) {
96108 * @param {Number } tagId - the data-brackets-id of the DOM element
97109 */
98110 function _deleteElementInSourceByTagId ( tagId ) {
99- const editor = EditorManager . getActiveEditor ( ) ;
111+ // this is to get the currently live document that is being served in the live preview
112+ const currLiveDoc = LiveDevMultiBrowser . getCurrentLiveDoc ( ) ;
113+ if ( ! currLiveDoc ) {
114+ return ;
115+ }
116+
117+ const editor = currLiveDoc . editor ;
100118 if ( ! editor || ! tagId ) {
101119 return ;
102120 }
0 commit comments