@@ -941,43 +941,17 @@ function isGhost(label) {
941941
942942function labelValidator ( textblock , oldstr , newstr ) {
943943 if ( newstr === oldstr ) return true ;
944- if ( newstr === "" ) return false ;
945- if ( ! isNaN ( newstr ) ) return false ;
946-
947-
944+ if ( ! newstr || ! isNaN ( newstr ) ) return false ;
948945
949946 if ( isGhost ( newstr ) ) {
950947 const targetLabel = newstr . substring ( 1 ) ;
951- const realNodeCount = myDiagram . model . nodeDataArray . filter ( node => node . label === targetLabel && node . label !== oldstr && ! isGhost ( node . label ) ) . length ;
952-
948+ const realNodeCount = myDiagram . model . nodeDataArray
949+ . filter ( node => node . label === targetLabel && ! isGhost ( node . label ) ) . length ;
953950 return realNodeCount >= 1 ;
954951 }
955952
956- const $tbody = $ ( '#eqTableBody' ) ;
957- $tbody . find ( 'tr' ) . each ( function ( ) {
958- const $row = $ ( this ) ;
959- const name = $row . find ( 'input[name="name"]' ) . val ( ) ;
960- if ( name === oldstr ) {
961- const equation = $row . find ( 'input[name="equation"]' ) . val ( ) ;
962- const checkbox = $row . find ( 'input[name="checkbox"]' ) . is ( ':checked' ) ;
963- $row . find ( 'input[name="name"]' ) . val ( newstr ) ;
964-
965- GOJS_ELEMENT_LABELS_SET . delete ( oldstr ) ;
966- GOJS_ELEMENT_LABELS_SET . add ( newstr ) ;
967- const index = GOJS_ELEMENT_LABELS . indexOf ( oldstr ) ;
968- if ( index !== - 1 ) GOJS_ELEMENT_LABELS [ index ] = newstr ;
969-
970- $row . data ( 'migrated' , { equation, checkbox} ) ;
971- }
972- } ) ;
973-
974- for ( let i = 0 ; i < myDiagram . model . nodeDataArray . length ; i ++ ) {
975- if ( myDiagram . model . nodeDataArray [ i ] . label === newstr ) {
976- return false ;
977- }
978- }
979-
980- return true ;
953+ // Ensure uniqueness
954+ return ! myDiagram . model . nodeDataArray . some ( n => n . label === newstr ) ;
981955}
982956
983957/**
@@ -1849,7 +1823,6 @@ function getTopBracketMatches(fragment) {
18491823 const lower = fragment . toLowerCase ( ) ;
18501824
18511825 if ( fragment === "" ) {
1852- // Show first 5 elements in creation order
18531826 return GOJS_ELEMENT_LABELS . slice ( 0 , 5 ) ;
18541827 }
18551828
@@ -1867,29 +1840,33 @@ function finalizeRename() {
18671840 if ( ! labelValidator ( null , oldName , newName ) ) {
18681841 showAlertPopup ( {
18691842 title : "Invalid or Duplicate Name" ,
1870- message : `The name "${ newName } " is invalid or already in use.\nIt will be reset to "${ oldName } ".` ,
1871- onConfirm : ( ) => {
1872-
1873- } ,
1843+ message : `The name "${ newName } " is invalid or already in use.\nIt will be reset to "${ oldName } ".`
18741844 } ) ;
18751845 $input . val ( oldName ) ;
18761846 return ;
18771847 }
18781848
1879-
1880- const escapeRegExp = ( string ) =>
1881- string . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) ;
1849+ // Grab only this row's data (no full-table overwrite)
1850+ const $row = $input . closest ( 'tr' ) ;
1851+ const equation = $row . find ( 'input[name="equation"]' ) . val ( ) ;
1852+ const checkbox = $row . find ( 'input[name="checkbox"]' ) . is ( ':checked' ) ;
18821853
18831854 myDiagram . model . commit ( ( ) => {
1855+ // Find the node being renamed
18841856 const nodeData = myDiagram . model . nodeDataArray . find ( n => n . label === oldName ) ;
18851857 if ( nodeData ) {
1858+ // Update label/key
18861859 myDiagram . model . setDataProperty ( nodeData , 'label' , newName ) ;
18871860 if ( nodeData . key === oldName ) {
18881861 myDiagram . model . setDataProperty ( nodeData , 'key' , newName ) ;
18891862 }
1863+ // Preserve/update equation + checkbox only for this node
1864+ myDiagram . model . setDataProperty ( nodeData , 'equation' , equation ) ;
1865+ myDiagram . model . setDataProperty ( nodeData , 'checkbox' , checkbox ) ;
18901866 }
18911867
1892- const pattern = new RegExp ( `\\[${ escapeRegExp ( oldName ) } \\]` , 'g' ) ;
1868+ // Update references in other nodes' equations
1869+ const pattern = new RegExp ( `\\[${ oldName . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) } \\]` , 'g' ) ;
18931870 myDiagram . model . nodeDataArray . forEach ( n => {
18941871 if ( typeof n . equation === 'string' ) {
18951872 const updated = n . equation . replace ( pattern , `[${ newName } ]` ) ;
@@ -1898,17 +1875,17 @@ function finalizeRename() {
18981875 }
18991876 }
19001877 } ) ;
1878+ } , 'Rename node' ) ;
19011879
1902- updateTable ( true ) ;
1903- } , 'Rename node and update references' ) ;
1880+ $input . data ( 'oldName' , newName ) ;
19041881
1905- $input . data ( 'oldName' , newName ) ; // Set for future renames
1882+ // Refresh table view from model without wiping unsaved edits in other rows
19061883 updateTable ( true ) ;
1907- myDiagram . requestUpdate ( ) ;
19081884}
19091885
19101886
19111887
1888+
19121889/**
19131890 * Sets up autocomplete functionality for all equation input fields in the equation table body.
19141891 * Handles showing suggestions on input, keyboard navigation, selection insertion,
0 commit comments