Skip to content

Instantly share code, notes, and snippets.

@d4rekanguok
Created October 11, 2018 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d4rekanguok/6b1c79f5972f3a8dfc192a31a25df8a9 to your computer and use it in GitHub Desktop.
Save d4rekanguok/6b1c79f5972f3a8dfc192a31a25df8a9 to your computer and use it in GitHub Desktop.
sketch plugin layer sort
var sketch = require('sketch/dom');
var document = sketch.getSelectedDocument();
var selection = document.selectedLayers.layers.slice();
selection
.sort((l1, l2) => {
var l1x = l1.frame.x,
l1y = l1.frame.y,
l2x = l2.frame.x,
l2y = l2.frame.y;
if (l1y > l2y) return 1;
if (l1y < l2y) return -1;
else {
if (l1x > l2x) return 1;
if (l1x < l2x) return -1;
else return 0;
}
})
.forEach(l => l.moveToBack());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment