@@ -136,9 +136,14 @@ let currentRowData = null;
136136 if ( message . key ) {
137137 const index = grid . rowsData . findIndex ( x => x . Key === message . key ) ;
138138 if ( index === - 1 ) {
139+ if ( ! grid . rowsData ) {
140+ grid . rowsData = [ ] ;
141+ }
139142 // eslint-disable-next-line @typescript-eslint/naming-convention
140143 grid . rowsData . push ( { Key : message . key , Value : message . value , Comment : message . comment } ) ;
141144 refreshResxData ( ) ;
145+ // Force grid to update by reassigning the rowsData
146+ grid . rowsData = [ ...grid . rowsData ] ;
142147 }
143148 else {
144149 // create vscode notification
@@ -176,38 +181,40 @@ let currentRowData = null;
176181 }
177182
178183 function updateContent ( /** @type {string } **/ text ) {
179- if ( text ) {
180-
181- var resxValues = [ ] ;
182-
183- let json ;
184- try {
185- json = JSON . parse ( text ) ;
186- }
187- catch
188- {
189- console . log ( "error parsing json" ) ;
190- return ;
191- }
192-
193- for ( const node in json || [ ] ) {
194- if ( node ) {
195- let res = json [ node ] ;
196- // eslint-disable-next-line @typescript-eslint/naming-convention
197- var item = { Key : node , "Value" : res . value || '' , "Comment" : res . comment || '' } ;
198- resxValues . push ( item ) ;
199- }
200- else {
201- console . log ( 'node is undefined or null' ) ;
202- }
203- }
184+ var resxValues = [ ] ;
204185
186+ if ( ! text || text . trim ( ) === '' ) {
187+ // Handle blank file by initializing with empty data
205188 grid . rowsData = resxValues ;
189+ return ;
206190 }
207- else {
208- console . log ( "text is null" ) ;
191+
192+ let json ;
193+ try {
194+ json = JSON . parse ( text ) ;
195+ }
196+ catch ( e ) {
197+ console . log ( "error parsing json:" , e ) ;
198+ vscode . postMessage ( {
199+ type : 'error' ,
200+ message : 'Error parsing resource file content'
201+ } ) ;
209202 return ;
210203 }
204+
205+ for ( const node in json || [ ] ) {
206+ if ( node ) {
207+ let res = json [ node ] ;
208+ // eslint-disable-next-line @typescript-eslint/naming-convention
209+ var item = { Key : node , "Value" : res . value || '' , "Comment" : res . comment || '' } ;
210+ resxValues . push ( item ) ;
211+ }
212+ else {
213+ console . log ( 'node is undefined or null' ) ;
214+ }
215+ }
216+
217+ grid . rowsData = resxValues ;
211218 }
212219
213220 const state = vscode . getState ( ) ;
0 commit comments