11import $ from 'jquery' ;
2- import jenkinsJSModules from 'jenkins-js-modules' ;
32// Polyfill for window.requestAnimationFrame
43import 'raf/polyfill' ;
54// Import the resizable module to allow the textarea to be expanded
65import 'jquery-ui/ui/widgets/resizable' ;
76import { addSamplesWidget } from './samples' ;
87
8+ // Import ACE
9+ import ace from "ace-builds/src-noconflict/ace" ;
10+ import "ace-builds/src-noconflict/ext-language_tools" ;
11+ import "ace-builds/src-noconflict/mode-groovy" ;
12+ import "ace-builds/src-noconflict/theme-tomorrow" ;
13+
14+ // Import custom snippets
15+ import "./snippets/workflow" ;
16+
917var editorIdCounter = 0 ;
1018
11- // The Jenkins 'ace-editor:ace-editor-122' plugin doesn't support a synchronous
12- // require option. This is because of how the ACE editor is written. So, we need
13- // to use lower level jenkins-js-modules async 'import' to get a handle on a
14- // specific version of ACE, from which we create an editor instance for workflow.
15- jenkinsJSModules . import ( 'ace-editor:ace-editor-122' )
16- . onFulfilled ( function ( acePack ) {
1719 $ ( '.workflow-editor-wrapper' ) . each ( function ( ) {
1820 initEditor ( $ ( this ) ) ;
1921 } ) ;
@@ -30,24 +32,18 @@ jenkinsJSModules.import('ace-editor:ace-editor-122')
3032 var editorId = 'workflow-editor-' + editorIdCounter ;
3133 aceContainer . attr ( 'id' , editorId ) ;
3234
33- // The 'ace-editor:ace-editor-122' plugin supplies an "ACEPack" object.
34- // ACEPack understands the hardwired async nature of the ACE impl and so
35- // provides some async ACE script loading functions.
36-
37- acePack . edit ( editorId , function ( ) {
38- var ace = acePack . ace ;
39- var editor = this . editor ;
35+ var editor = ace . edit ( editorId ) ;
4036
4137 // Attach the ACE editor instance to the element. Useful for testing.
4238 var $wfEditor = $ ( '#' + editorId ) ;
4339 $wfEditor . get ( 0 ) . aceEditor = editor ;
4440
45- acePack . addPackOverride ( 'snippets/groovy.js' , '../workflow-cps/snippets/workflow.js' ) ;
41+ // https://stackoverflow.com/a/66923593
42+ var snippetManager = ace . require ( 'ace/snippets' ) . snippetManager ;
43+ var snippetContent = ace . require ( 'ace/snippets/groovy' ) . snippetText ;
44+ var snippets = snippetManager . parseSnippetFile ( snippetContent ) ;
45+ snippetManager . register ( snippets , 'groovy' ) ;
4646
47- acePack . addScript ( 'ext-language_tools.js' , function ( ) {
48- ace . require ( "ace/ext/language_tools" ) ;
49-
50- editor . $blockScrolling = Infinity ;
5147 editor . session . setMode ( "ace/mode/groovy" ) ;
5248 editor . setTheme ( "ace/theme/tomorrow" ) ;
5349 editor . setAutoScrollEditorIntoView ( true ) ;
@@ -60,7 +56,7 @@ jenkinsJSModules.import('ace-editor:ace-editor-122')
6056 } ) ;
6157
6258 editor . setValue ( textarea . val ( ) , 1 ) ;
63- editor . getSession ( ) . on ( 'change' , function ( ) {
59+ editor . getSession ( ) . on ( 'change' , function ( delta ) {
6460 textarea . val ( editor . getValue ( ) ) ;
6561 showSamplesWidget ( ) ;
6662 } ) ;
@@ -108,7 +104,6 @@ jenkinsJSModules.import('ace-editor:ace-editor-122')
108104 }
109105 }
110106 showSamplesWidget ( ) ;
111- } ) ;
112107
113108 // Make the editor resizable using jQuery UI resizable (http://api.jqueryui.com/resizable).
114109 // ACE Editor doesn't have this as a config option.
@@ -129,9 +124,7 @@ jenkinsJSModules.import('ace-editor:ace-editor-122')
129124 } )
130125 } ,
131126 } ) ;
132- } ) ;
133127
134128 wrapper . show ( ) ;
135129 textarea . hide ( ) ;
136130 }
137- } ) ;
0 commit comments