1- /* global CodeMirror, Prism */
1+ /* global Prism */
22'use strict' ;
33
44const api = require ( '../../api' ) ;
55const template = require ( './chat-message-script.html' ) ;
6+ const { createAceEditor, destroyAceEditor } = require ( '../../aceEditor' ) ;
67
78module . exports = app => app . component ( 'chat-message-script' , {
89 template,
@@ -68,16 +69,20 @@ module.exports = app => app.component('chat-message-script', {
6869 this . showCreateDashboardModal = true ;
6970 this . $nextTick ( ( ) => {
7071 if ( this . dashboardEditor ) {
71- this . dashboardEditor . toTextArea ( ) ;
72+ destroyAceEditor ( this . dashboardEditor ) ;
73+ this . dashboardEditor = null ;
74+ }
75+ const container = this . $refs . dashboardCodeEditor ;
76+ if ( container ) {
77+ this . dashboardEditor = createAceEditor ( container , {
78+ value : this . dashboardCode ,
79+ mode : 'javascript' ,
80+ lineNumbers : true
81+ } ) ;
82+ this . dashboardEditor . session . on ( 'change' , ( ) => {
83+ this . dashboardCode = this . dashboardEditor . getValue ( ) ;
84+ } ) ;
7285 }
73- this . $refs . dashboardCodeEditor . value = this . dashboardCode ;
74- this . dashboardEditor = CodeMirror . fromTextArea ( this . $refs . dashboardCodeEditor , {
75- mode : 'javascript' ,
76- lineNumbers : true
77- } ) ;
78- this . dashboardEditor . on ( 'change' , ( ) => {
79- this . dashboardCode = this . dashboardEditor . getValue ( ) ;
80- } ) ;
8186 } ) ;
8287 } ,
8388 openOverwriteDashboardConfirmation ( ) {
@@ -95,35 +100,33 @@ module.exports = app => app.component('chat-message-script', {
95100 this . isEditing = true ;
96101 this . editedScript = this . script ;
97102 this . $nextTick ( ( ) => {
98- if ( ! this . $refs . scriptEditor ) {
99- return ;
100- }
101- this . $refs . scriptEditor . value = this . editedScript ;
102- if ( typeof CodeMirror === 'undefined' ) {
103- return ;
104- }
105- this . destroyCodeMirror ( ) ;
106- this . codeEditor = CodeMirror . fromTextArea ( this . $refs . scriptEditor , {
103+ const container = this . $refs . scriptEditor ;
104+ if ( ! container ) return ;
105+ this . destroyAceEditor ( ) ;
106+ this . codeEditor = createAceEditor ( container , {
107+ value : this . editedScript ,
107108 mode : 'javascript' ,
108- lineNumbers : true ,
109- smartIndent : false
109+ lineNumbers : true
110+ } ) ;
111+ this . codeEditor . session . on ( 'change' , ( ) => {
112+ this . editedScript = this . codeEditor . getValue ( ) ;
110113 } ) ;
111114 } ) ;
112115 } ,
113116 cancelEditing ( ) {
114117 this . isEditing = false ;
115- this . destroyCodeMirror ( ) ;
118+ this . destroyAceEditor ( ) ;
116119 this . editedScript = this . script ;
117120 this . highlightCode ( ) ;
118121 } ,
119122 finishEditing ( ) {
120123 this . isEditing = false ;
121- this . destroyCodeMirror ( ) ;
124+ this . destroyAceEditor ( ) ;
122125 this . highlightCode ( ) ;
123126 } ,
124- destroyCodeMirror ( ) {
127+ destroyAceEditor ( ) {
125128 if ( this . codeEditor ) {
126- this . codeEditor . toTextArea ( ) ;
129+ destroyAceEditor ( this . codeEditor ) ;
127130 this . codeEditor = null ;
128131 }
129132 } ,
@@ -211,7 +214,7 @@ module.exports = app => app.component('chat-message-script', {
211214 watch : {
212215 showCreateDashboardModal ( val ) {
213216 if ( ! val && this . dashboardEditor ) {
214- this . dashboardEditor . toTextArea ( ) ;
217+ destroyAceEditor ( this . dashboardEditor ) ;
215218 this . dashboardEditor = null ;
216219 }
217220 } ,
@@ -232,7 +235,7 @@ module.exports = app => app.component('chat-message-script', {
232235 }
233236 } ,
234237 unmounted ( ) {
235- this . destroyCodeMirror ( ) ;
238+ this . destroyAceEditor ( ) ;
236239 document . body . removeEventListener ( 'click' , this . handleBodyClick ) ;
237240 }
238241} ) ;
0 commit comments