Reversed layer ordering
chpio opened this issue · 2 comments
chpio commented
Hi,
I have those layers in sketch:
- "a"
- "b"
- "c"
But when im accessing them via the js api im getting the layers in reversed order:
- "c"
- "b"
- "a"
Artboards are also reversed.
test code:
import sketch from "sketch";
sketch.getSelectedDocument()?.pages
.flatMap((page) => page.layers)
.filter(createIsInstanceOf(sketch.Artboard))
.forEach((ab) => {
console.log(`start ab "${ab.name}"`);
ab.layers.forEach((l) => {
console.log(` layer "${l.name}"`);
});
console.log(`end ab "${ab.name}"`);
});
function createIsInstanceOf<T, S extends T>(klass: new () => S): (val: T) => val is S {
return function isInstanceOf(val: T): val is S {
return val instanceof klass;
};
}
sketch version: 70.3 (i think i had this error already with v68 or something)
chpio commented
https://github.com/skpm/sketch-dev-tools shows all layers in the "Elements" tab in reversed order too
christianklotz commented
Layers are enumerated bottom-up, the bottom-most is index 0
, and everything else on top of that has a higher index, similar to CSS z-index, etc. This is expected behaviour, closing.