i'm pretty sure this does what you want, but please sanity-check the code and test it out interactively, i'm in a weird library with astonishingly bad wifi so i wasn't super-able to do a lot of interactive testing on this. also moved restoreSort into redrawTrackList since it looks like the former is called every time you call the latter, but feel free to undo that change if you think it's incorrect, i didn't 100% confirm that that was a sane thing to do. let me know if this didn't do what you were hoping for!
i'm pretty sure this does what you want, but please sanity-check the code and test it out interactively, i'm in a weird library with astonishingly bad wifi so i wasn't super-able to do a lot of interactive testing on this. also moved restoreSort into redrawTrackList since it looks like the former is called every time you call the latter, but feel free to undo that change if you think it's incorrect, i didn't 100% confirm that that was a sane thing to do. let me know if this didn't do what you were hoping for!