[HELP] Tab patch messes up order

The way I have this patch set up should make the tab order to go Scripts, Costumes, Sounds, and FX inspector. Except, Scripts is all the way before FX inspector.

// monkey-patch sprite bar creation
window.onerror = error => world.hint(error)

window.csbPrepatch = window.csbPrepatch || IDE_Morph.prototype.createSpriteBar;

window.csbPrepatch.apply(world.children[0]);

IDE_Morph.prototype.createSpriteBar = function (...args) {
    const result = csbPrepatch.apply(this, args) // run the prepatched function

    let tabBar = this.spriteBar.tabBar
    let tab = new TabMorph(
        this.tabColors,
        null, // target
        () => tabBar.tabTo('effects'),
        [ // label
            new SymbolMorph('notes', 10),
            localize('FX inspector')
        ],
        () => this.currentTab === 'effects' // query
    );
    tab.padding = 3;
    tab.corner = 15;
    tab.edge = 1;
    tab.labelShadowOffset = new Point(-1, -1);
    tab.labelShadowColor = this.tabColors[1];
    tab.labelColor = this.buttonLabelColor;
    tab.fixLayout();

    tabBar.add(tab);

    tabBar.fixLayout();

    return result
}

image
As you can see, Scripts is not at the start of the tabs - where it should be.

Can anyone with a keen eye figure out the actual problem with this, or should I resort to what 3D Beetle did with the 3D window button in the palette?

Try switching over to a tab like costumes before applying the patch. That should tell if whatever the current tab is whatever gets pushed to the top or just scripts.

And also, why do you apply before doing the patch? Shouldn’t you just keep it the way it is? If you need to refresh the IDE, I think you can call refreshIDE to recreate everything.

I tested it. The selected tab does get pushed to the top.

Well… my solution sucks, but it works for now.

Instead of reordering the tabs, I just removed them all and rebuilt them.

download