Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
Only accept positive values
Browse files Browse the repository at this point in the history
  • Loading branch information
mikegowen committed Jan 26, 2015
1 parent ba321eb commit 4df6013
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions Pull to center.sketchplugin
Expand Up @@ -18,18 +18,22 @@ if (hasValidSelection && hasValidSelectionCount && hasSingleArtboardParents) {
artboardCenterX = artboardWidth / 2,
artboardCenterY = artboardHeight / 2;
var distance = [doc askForUserInput:"Distance to move (pixels):" initialValue:"0"];
var loop = [selection objectEnumerator];

while (selectionItem = [loop nextObject]) {
var layer = selectionItem,
frame = [layer frame],
selectionWidth = [frame width],
selectionHeight = [frame height],
selectionX = [frame x],
selectionY = [frame y],
selectionCenteredX = selectionX + (selectionWidth / 2),
selectionCenteredY = selectionY + (selectionHeight / 2);
move(selectionItem, artboardCenterX, artboardCenterY, selectionCenteredX, selectionCenteredY, distance);
if (distance > 0) {
var loop = [selection objectEnumerator];
while (selectionItem = [loop nextObject]) {
var layer = selectionItem,
frame = [layer frame],
selectionWidth = [frame width],
selectionHeight = [frame height],
selectionX = [frame x],
selectionY = [frame y],
selectionCenteredX = selectionX + (selectionWidth / 2),
selectionCenteredY = selectionY + (selectionHeight / 2);
move(selectionItem, artboardCenterX, artboardCenterY, selectionCenteredX, selectionCenteredY, distance);
}
} else {
[doc showMessage:"Please enter a positive distance."];
}
}

Expand Down

0 comments on commit 4df6013

Please sign in to comment.