161161 } )
162162 }
163163
164+ const ensureEditorStyles = ( ) => {
165+ if ( document . getElementById ( 'knxUltimateEditorHighlight' ) ) return ;
166+ const style = document . createElement ( 'style' ) ;
167+ style . id = 'knxUltimateEditorHighlight' ;
168+ style . textContent = `
169+ .ace_editor.knx-highlight .ace_content { background-color: #e6ffe6 !important; }
170+ .monaco-editor.knx-highlight .overflow-guard { background-color: #e6ffe6 !important; }
171+ ` ;
172+ document . head . appendChild ( style ) ;
173+ } ;
174+ ensureEditorStyles ( ) ;
175+
176+ const applyEditorOptions = ( editor ) => {
177+ try {
178+ if ( ! editor ) return ;
179+ if ( typeof editor . updateOptions === 'function' ) {
180+ editor . updateOptions ( { lineNumbers : 'off' , minimap : { enabled : false } , scrollbar : { verticalScrollbarSize : 8 , horizontalScrollbarSize : 8 } } ) ;
181+ } else if ( editor . renderer && typeof editor . renderer . setShowGutter === 'function' ) {
182+ editor . renderer . setShowGutter ( false ) ;
183+ }
184+ if ( typeof editor . setShowPrintMargin === 'function' ) editor . setShowPrintMargin ( false ) ;
185+ } catch ( error ) { }
186+ } ;
187+
188+ const highlightEditor = ( editor , active ) => {
189+ if ( ! editor ) return ;
190+ try {
191+ if ( editor . renderer && typeof editor . renderer . setStyle === 'function' ) {
192+ const cls = 'knx-highlight' ;
193+ if ( active ) editor . renderer . setStyle ( cls ) ; else editor . renderer . unsetStyle ( cls ) ;
194+ } else if ( typeof editor . getDomNode === 'function' ) {
195+ const dom = editor . getDomNode ( ) ;
196+ if ( dom ) {
197+ if ( active ) dom . classList . add ( 'knx-highlight' ) ; else dom . classList . remove ( 'knx-highlight' ) ;
198+ }
199+ }
200+ } catch ( error ) { }
201+ } ;
202+
203+ const attachFocusHandlers = ( editor ) => {
204+ if ( ! editor ) return ;
205+ try {
206+ if ( typeof editor . on === 'function' && editor . renderer ) {
207+ editor . on ( 'focus' , ( ) => { node . activeCodeEditor = editor ; highlightEditor ( editor , true ) ; } ) ;
208+ editor . on ( 'blur' , ( ) => highlightEditor ( editor , false ) ) ;
209+ } else if ( typeof editor . onDidFocusEditorWidget === 'function' ) {
210+ editor . onDidFocusEditorWidget ( ( ) => { node . activeCodeEditor = editor ; highlightEditor ( editor , true ) ; } ) ;
211+ if ( typeof editor . onDidBlurEditorWidget === 'function' ) {
212+ editor . onDidBlurEditorWidget ( ( ) => highlightEditor ( editor , false ) ) ;
213+ }
214+ }
215+ } catch ( error ) { }
216+ } ;
217+
218+ const insertTextIntoEditor = ( editor , text ) => {
219+ if ( ! editor || ! text ) return ;
220+ try {
221+ if ( editor . session && typeof editor . session . insert === 'function' ) {
222+ editor . focus ( ) ;
223+ editor . session . insert ( editor . getCursorPosition ( ) , text ) ;
224+ return ;
225+ }
226+ if ( typeof editor . executeEdits === 'function' && typeof editor . getPosition === 'function' && typeof monaco !== 'undefined' ) {
227+ const position = editor . getPosition ( ) ;
228+ if ( ! position ) return ;
229+ const range = new monaco . Range ( position . lineNumber , position . column , position . lineNumber , position . column ) ;
230+ editor . executeEdits ( 'knxInsertGA' , [ { range, text, forceMoveMarkers : true } ] ) ;
231+ editor . setPosition ( { lineNumber : position . lineNumber , column : position . column + text . length } ) ;
232+ editor . focus ( ) ;
233+ }
234+ } catch ( error ) { }
235+ } ;
236+
164237 node . sendMsgToKNXCodeEditor = RED . editor . createEditor ( {
165238 id : 'sendMsgToKNXCode-editor' ,
166239 mode : 'ace/mode/nrjavascript' ,
167240 value : node . sendMsgToKNXCode
168241 } ) ;
242+ applyEditorOptions ( node . sendMsgToKNXCodeEditor ) ;
169243 node . receiveMsgFromKNXCodeEditor = RED . editor . createEditor ( {
170244 id : 'receiveMsgFromKNXCode-editor' ,
171245 mode : 'ace/mode/nrjavascript' ,
172246 value : node . receiveMsgFromKNXCode
173247 } ) ;
248+ applyEditorOptions ( node . receiveMsgFromKNXCodeEditor ) ;
174249 node . activeCodeEditor = null ;
175- try {
176- node . sendMsgToKNXCodeEditor . on ( 'focus' , function ( ) {
177- node . activeCodeEditor = node . sendMsgToKNXCodeEditor ;
178- } ) ;
179- node . receiveMsgFromKNXCodeEditor . on ( 'focus' , function ( ) {
180- node . activeCodeEditor = node . receiveMsgFromKNXCodeEditor ;
181- } ) ;
182- } catch ( error ) { }
250+ attachFocusHandlers ( node . sendMsgToKNXCodeEditor ) ;
251+ attachFocusHandlers ( node . receiveMsgFromKNXCodeEditor ) ;
183252
184253 $ ( "#btn-insert-knxFunctionGA" ) . off ( 'click' ) . on ( 'click' , function ( ) {
185254 const value = $ ( "#node-input-knxFunctionHelperGAList" ) . val ( ) ;
189258 }
190259 const editor = node . activeCodeEditor || node . sendMsgToKNXCodeEditor || node . receiveMsgFromKNXCodeEditor ;
191260 if ( ! editor ) return ;
192- try {
193- editor . focus ( ) ;
194- editor . session . insert ( editor . getCursorPosition ( ) , value ) ;
195- } catch ( error ) { }
261+ insertTextIntoEditor ( editor , value ) ;
196262 } ) ;
197263
198264 const configureSnippetPicker = ( snippets , inputSelector , datalistSelector , applySnippet ) => {
921987 < i class = "fa fa-search" > </ i > < span data-i18n = "knxUltimate.snippets.searchGA" > </ span >
922988 </ label >
923989 < input type = "text" id = "node-input-knxFunctionHelperGAList"
924- data-i18n = "[placeholder]knxUltimate.placeholder.search" style = "max -width:280px ;" />
990+ data-i18n = "[placeholder]knxUltimate.placeholder.search" style = "min -width:260px ;" />
925991 < button type = "button" class = "red-ui-button" id = "btn-insert-knxFunctionGA" title = "Insert"
926992 style = "margin-left:4px;" >
927993 < i class = "fa fa-level-down" > </ i >
9771043 </ div >
9781044</ div >
9791045< br /> < br />
980- </ script >
1046+ </ script >
0 commit comments