@@ -89,6 +89,8 @@ interface IStates {
89
89
selectedNodes : string [ ] ;
90
90
clientId : number | null ; // ID of the yjs client
91
91
id : string ; // ID of the component, it is used to identify which component
92
+ editingNode : TreeNodeId | null ;
93
+ editingNodeValue : string | null ;
92
94
//is the source of awareness updates.
93
95
openNodes : ( number | string ) [ ] ;
94
96
}
@@ -154,7 +156,9 @@ class ObjectTreeReact extends React.Component<IProps, IStates> {
154
156
selectedNodes : [ ] ,
155
157
clientId : null ,
156
158
id : uuid ( ) ,
157
- openNodes : [ ]
159
+ openNodes : [ ] ,
160
+ editingNode : null ,
161
+ editingNodeValue : ''
158
162
} ;
159
163
this . props . cpModel . jcadModel ?. sharedObjectsChanged . connect (
160
164
this . _sharedJcadModelChanged
@@ -464,9 +468,54 @@ class ObjectTreeReact extends React.Component<IProps, IStates> {
464
468
textOverflow : 'ellipsis' ,
465
469
overflowX : 'hidden'
466
470
} }
471
+ onClick = { ( ) => this . setState ( { editingNode : opts . node . id } ) }
467
472
>
468
- { opts . node . label }
469
- </ span >
473
+ { this . state . editingNode === opts . node . id ? (
474
+ < input
475
+ type = "text"
476
+ value = { this . state . editingNodeValue || opts . node . label }
477
+ autoFocus
478
+ onBlur = { ( ) => this . setState ( { editingNode : null } ) }
479
+ onChange = { ( e ) =>
480
+ this . setState ( { editingNodeValue : e . target . value } )
481
+ }
482
+ onKeyDown = { ( e ) => {
483
+ if ( e . key === 'Enter' ) {
484
+ console . log ( 'Updated name:' , this . state . editingNodeValue ) ;
485
+ const updatedName = this . state . editingNodeValue ;
486
+ const objectName = opts . node . id ;
487
+
488
+ if ( this . props . cpModel . mainViewModel ) {
489
+ const obj = this . props . cpModel . jcadModel ?. sharedModel . getObjectByName ( objectName as string ) ;
490
+ if ( obj ) {
491
+ this . props . cpModel . sharedModel ?. updateObjectByName ( objectName as string , {
492
+ data : {
493
+ key : 'name' ,
494
+ value : updatedName
495
+ }
496
+ }
497
+ ) ;
498
+ }
499
+ }
500
+ this . setState ( {
501
+ editingNode : null ,
502
+ editingNodeValue : null
503
+ } ) ;
504
+ }
505
+ } }
506
+ style = { {
507
+ width : '100%' ,
508
+ background : 'transparent' ,
509
+ border : 'none' ,
510
+ outline : 'none' ,
511
+ fontSize : 'inherit' ,
512
+ color : 'inherit'
513
+ } }
514
+ />
515
+ ) : (
516
+ opts . node . label
517
+ ) }
518
+ </ span >
470
519
{ opts . type === 'leaf' ? (
471
520
< div style = { { display : 'flex' } } >
472
521
< ToolbarButtonComponent
0 commit comments