@@ -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,8 +468,61 @@ 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 }
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 (
485
+ 'Updated name:' ,
486
+ this . state . editingNodeValue
487
+ ) ;
488
+ const updatedName = this . state . editingNodeValue ;
489
+ const objectName = opts . node . id ;
490
+
491
+ if ( this . props . cpModel . mainViewModel ) {
492
+ const obj =
493
+ this . props . cpModel . jcadModel ?. sharedModel . getObjectByName (
494
+ objectName as string
495
+ ) ;
496
+ if ( obj ) {
497
+ this . props . cpModel . sharedModel ?. updateObjectByName (
498
+ objectName as string ,
499
+ {
500
+ data : {
501
+ key : 'name' ,
502
+ value : updatedName
503
+ }
504
+ }
505
+ ) ;
506
+ }
507
+ }
508
+ this . setState ( {
509
+ editingNode : null ,
510
+ editingNodeValue : null
511
+ } ) ;
512
+ }
513
+ } }
514
+ style = { {
515
+ width : '100%' ,
516
+ background : 'transparent' ,
517
+ border : 'none' ,
518
+ outline : 'none' ,
519
+ fontSize : 'inherit' ,
520
+ color : 'inherit'
521
+ } }
522
+ />
523
+ ) : (
524
+ opts . node . label
525
+ ) }
469
526
</ span >
470
527
{ opts . type === 'leaf' ? (
471
528
< div style = { { display : 'flex' } } >
0 commit comments