@@ -41,6 +41,7 @@ export class Editor {
4141 private handIcon : HandIcon ;
4242
4343 protected objs :Node [ ] = [ ] ;
44+ protected zSortedObjs :Node [ ] = [ ] ;
4445 readonly connections :Connection [ ] = [ ] ;
4546
4647 /**
@@ -217,12 +218,12 @@ export class Editor {
217218
218219 this . selectedOutlet = undefined ;
219220 this . eventsHandler = undefined ;
220-
221+
221222 //
222223 // let's see if some canvas element wants to capture the mouse....
223224 //
224- for ( const obj of this . objs ) {
225-
225+ for ( const obj of this . zSortedObjs ) {
226+ console . log ( obj )
226227 //#region OUTLET
227228 //
228229 // check if mouse if over an outlet to create/delete a connection
@@ -269,12 +270,15 @@ export class Editor {
269270 //#endregion
270271
271272 //
273+ // CURSOR IS INSIDE THE WINDOW NODE
272274 // default: mouse down on the node window.
273275 //
274276 if ( cursor . x > obj . x && cursor . x < obj . x + obj . width ( this . ctx ) && cursor . y > obj . y && cursor . y < obj . y + obj . height ( this . ctx ) )
275277 {
276278 // default... will make the object move...
277279 this . focusedChild = obj ;
280+ this . bingToTop ( obj ) ;
281+ break ; //<-- to avoid processing childrens under us....
278282 }
279283
280284 } ;
@@ -386,9 +390,25 @@ export class Editor {
386390 return this . _ctx ;
387391 }
388392
393+ protected bingToTop ( node :Node ) {
394+ const nodeIndexZ = this . zSortedObjs . indexOf ( node ) ;
395+ const nodeIndex = this . objs . indexOf ( node ) ;
396+
397+ if ( nodeIndexZ !== - 1 ) {
398+ this . zSortedObjs . splice ( nodeIndexZ , 1 ) ;
399+ this . zSortedObjs . unshift ( node ) ;
400+ }
401+
402+ if ( nodeIndex !== - 1 ) {
403+ this . objs . splice ( nodeIndex , 1 ) ;
404+ this . objs . push ( node ) ;
405+ }
406+ }
407+
389408 add ( node :Node ) {
390409 node . editor = this ;
391410 this . objs . push ( node ) ;
411+ this . zSortedObjs . unshift ( node ) ;
392412 }
393413
394414 protected clickElementAt ( globalPos :Vector2Like , root :LayoutElement )
0 commit comments