@@ -290,6 +290,17 @@ Open up the challenge in your favorite code editor and follow the instructions i
290
290
return existsSync ( targetDir ) ;
291
291
}
292
292
293
+ rebuildHistory ( ) :void {
294
+ // Rebuild Global tree
295
+ this . globalTree = this . buildTree ( ) ;
296
+ // For each node in the current history, find the new node in the newly created tree
297
+ const newHistory = this . history . map ( ( { node, selection } ) => {
298
+ const newNode = this . findNode ( this . globalTree , node . name ) ;
299
+ return { node : newNode as TreeNode , selection } ;
300
+ } ) ;
301
+ this . history = newHistory ;
302
+ }
303
+
293
304
getChallengeActions ( challenge : TreeNode ) : Actions {
294
305
const actions : Actions = { } ;
295
306
const { address, installLocation } = this . userState ;
@@ -298,14 +309,12 @@ Open up the challenge in your favorite code editor and follow the instructions i
298
309
actions [ "Setup Challenge Repository" ] = async ( ) => {
299
310
this . clearView ( ) ;
300
311
await setupChallenge ( name , installLocation ) ;
301
- // Rebuild the tree
302
- this . globalTree = this . buildTree ( ) ;
312
+ // Rebuild the tree and history
313
+ this . rebuildHistory ( ) ;
303
314
// Wait for enter key
304
315
await this . pressEnterToContinue ( ) ;
305
- this . history . pop ( ) ; // Remove the old node from history since it has different actions
306
316
// Return to challenge menu
307
- const challengeNode = this . findNode ( this . globalTree , name ) as TreeNode ;
308
- await this . navigate ( challengeNode ) ;
317
+ await this . goBack ( ) ;
309
318
} ;
310
319
} else {
311
320
actions [ "Reset Challenge" ] = async ( ) => {
@@ -319,12 +328,11 @@ Open up the challenge in your favorite code editor and follow the instructions i
319
328
rmSync ( targetDir , { recursive : true , force : true } ) ;
320
329
console . log ( `Installing fresh copy of challenge...` ) ;
321
330
await setupChallenge ( name , installLocation ) ;
322
- this . globalTree = this . buildTree ( ) ;
331
+ // Rebuild the tree and history
332
+ this . rebuildHistory ( ) ;
323
333
await this . pressEnterToContinue ( ) ;
324
- this . history . pop ( ) ; // Remove the old node from history since it has different actions
325
334
// Return to challenge menu
326
- const challengeNode = this . findNode ( this . globalTree , name ) as TreeNode ;
327
- await this . navigate ( challengeNode ) ;
335
+ await this . goBack ( ) ;
328
336
}
329
337
} ;
330
338
actions [ "Submit Completed Challenge" ] = async ( ) => {
@@ -336,14 +344,12 @@ Open up the challenge in your favorite code editor and follow the instructions i
336
344
this . userState . challenges = newUserState . challenges ;
337
345
// Save the new user state locally
338
346
await saveUserState ( this . userState ) ;
339
- // Rebuild the tree
340
- this . globalTree = this . buildTree ( ) ;
347
+ // Rebuild the tree and history
348
+ this . rebuildHistory ( ) ;
341
349
// Wait for enter key
342
350
await this . pressEnterToContinue ( ) ;
343
- this . history . pop ( ) ; // Remove the old node from history since it has different actions
344
351
// Return to challenge menu
345
- const challengeNode = this . findNode ( this . globalTree , name ) as TreeNode ;
346
- await this . navigate ( challengeNode ) ;
352
+ await this . goBack ( ) ;
347
353
} ;
348
354
}
349
355
return actions ;
0 commit comments