11/**
2- * Copyright 2013 IBM Corp.
2+ * Copyright 2013, 2015 IBM Corp.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -72,6 +72,19 @@ RED.library = (function() {
7272 var selectedLibraryItem = null ;
7373 var libraryEditor = null ;
7474
75+ // Orion editor has set/getText
76+ // ACE editor has set/getValue
77+ // normalise to set/getValue
78+ if ( options . editor . setText ) {
79+ // Orion doesn't like having pos passed in, so proxy the call to drop it
80+ options . editor . setValue = function ( text , pos ) {
81+ options . editor . setText . call ( options . editor , text ) ;
82+ }
83+ }
84+ if ( options . editor . getText ) {
85+ options . editor . getValue = options . editor . getText ;
86+ }
87+
7588 function buildFileListItem ( item ) {
7689 var li = document . createElement ( "li" ) ;
7790 li . onmouseover = function ( e ) { $ ( this ) . addClass ( "list-hover" ) ; } ;
@@ -119,7 +132,7 @@ RED.library = (function() {
119132 $ ( this ) . addClass ( "list-selected" ) ;
120133 $ . get ( "library/" + options . url + root + item . fn , function ( data ) {
121134 selectedLibraryItem = item ;
122- libraryEditor . setText ( data ) ;
135+ libraryEditor . setValue ( data , - 1 ) ;
123136 } ) ;
124137 }
125138 } ) ( ) ;
@@ -144,7 +157,7 @@ RED.library = (function() {
144157 $ ( "#node-select-library" ) . children ( ) . remove ( ) ;
145158 var bc = $ ( "#node-dialog-library-breadcrumbs" ) ;
146159 bc . children ( ) . first ( ) . nextAll ( ) . remove ( ) ;
147- libraryEditor . setText ( '' ) ;
160+ libraryEditor . setValue ( '' , - 1 ) ;
148161
149162 $ . getJSON ( "library/" + options . url , function ( data ) {
150163 $ ( "#node-select-library" ) . append ( buildFileList ( "/" , data ) ) ;
@@ -205,14 +218,18 @@ RED.library = (function() {
205218 e . preventDefault ( ) ;
206219 } ) ;
207220
208- require ( [ "orion/editor/edit" ] , function ( edit ) {
209- libraryEditor = edit ( {
210- parent :document . getElementById ( 'node-select-library-text' ) ,
211- lang :"js" ,
212- readonly : true
213- } ) ;
221+ libraryEditor = ace . edit ( 'node-select-library-text' ) ;
222+ libraryEditor . setTheme ( "ace/theme/tomorrow" ) ;
223+ if ( options . mode ) {
224+ libraryEditor . getSession ( ) . setMode ( options . mode ) ;
225+ }
226+ libraryEditor . setOptions ( {
227+ readOnly : true ,
228+ highlightActiveLine : false ,
229+ highlightGutterLine : false
214230 } ) ;
215-
231+ libraryEditor . renderer . $cursorLayer . element . style . opacity = 0 ;
232+ libraryEditor . $blockScrolling = Infinity ;
216233
217234 $ ( "#node-dialog-library-lookup" ) . dialog ( {
218235 title : options . type + " library" ,
@@ -229,7 +246,7 @@ RED.library = (function() {
229246 var field = options . fields [ i ] ;
230247 $ ( "#node-input-" + field ) . val ( selectedLibraryItem [ field ] ) ;
231248 }
232- options . editor . setText ( libraryEditor . getText ( ) ) ;
249+ options . editor . setValue ( libraryEditor . getValue ( ) , - 1 ) ;
233250 }
234251 $ ( this ) . dialog ( "close" ) ;
235252 }
@@ -304,7 +321,7 @@ RED.library = (function() {
304321 }
305322 }
306323
307- data . text = options . editor . getText ( ) ;
324+ data . text = options . editor . getValue ( ) ;
308325 $ . ajax ( {
309326 url :"library/" + options . url + '/' + fullpath ,
310327 type : "POST" ,
0 commit comments