Incorrect default sketch opened when starting IDE

I expect it to open "SavedSketch2", since that is the last saved sketch that was open in Arduino IDE (step 18 of the demo).


Here is how the data is recorded:

  1. When you open a saved sketch in Arduino IDE, its path is prepended to the recentRoots[] array in C:\Users\<username>\.arduinoIDE\recentworkspace.json.
  2. When you exit Arduino IDE, the paths of all open saved sketches are saved to the workspaces[*].file fields in C:\Users\<username>\AppData\Roaming\arduino-ide\config.json.

Here is how that data is used on IDE startup:

Even though it is very deterministic, there is some inconsistency:

  • Sketches restored when the config.json data is used are the sketches that were open at the time of IDE exit, but the sketch restored when the recentworkspace.json data is used is not necessarily one that was open at exit (because the recentworkspace.json data is recorded when the sketch is opened).
  • The fallback behavior when the sketches to be restored can't be loaded is always to open a new sketch, even though there might be a sketch available in the recentworkspace.json data to restore. This is why a new sketch opens at step (25) of my demo, but then if you close the IDE and start it again a saved sketch will be restored.

Even so, I don't see that the inconsistency significantly harms the user experience. The inconsistencies I listed above occur under fairly uncommon conditions.