Created
October 11, 2018 04:55
-
-
Save d4rekanguok/6b1c79f5972f3a8dfc192a31a25df8a9 to your computer and use it in GitHub Desktop.
sketch plugin layer sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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