Was struggling with React, so thought I’d give a try with a simple JS UXP plugin, but again ran into a weird issue with layer ordering.
In my index.js (main in manifest) I have two simple commands:
app.activeDocument.layerTree.moveAbove( app.activeDocument.layerTree ); app.activeDocument.layerTree.moveBelow( app.activeDocument.layerTree );
This is how layers look like before these two are executed:
And this is how it looks after:
In this case
app.activeDocument.layerTree is the “On top 1” layer and
app.activeDocument.layerTree - “On top 2”. First command moves “On top 1” above the zero-index layer (to the very top). Second one should move “On top 2” below the new zero-index (first) layer, but instead in moves to the top again.
.layerTree doesn’t get reindexed or something, but it also doesn’t make sense, because indexes still doesn’t match. And moving below shouldn’t move up anyway.
Noticed this with more layers while looping in a forEach, but managed to simplify to just these two commands to reproduce the issue. Even if this happens almost all of the time, sometimes layers are ordered even more randomly after these two commands
Spent probably around 8 hours trying to figure out why, how and what is happening with no luck at all. Any help is appreciated.