Skip to content

Commit

Permalink
Smarter selection, select groups, artboards etc
Browse files Browse the repository at this point in the history
  • Loading branch information
margusholland committed Nov 14, 2015
1 parent c267d23 commit a7aff86
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Comma Fucker.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"title": "Comma, Fucker"
},
"identifier": "com.margusholland.commafucker",
"version": "1.0",
"version": "1.1",
"description": "Set of commands to clean up and modify text layers.",
"authorEmail": "margusholland@me.com",
"name": "Comma, Fucker",
Expand Down
25 changes: 23 additions & 2 deletions Comma Fucker.sketchplugin/Contents/Sketch/script.cocoascript
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,34 @@ var layers = function(context) {
var selectedLayers = context.selection
var selectedCount = doc.selectedLayersOfClass(MSTextLayer).count()
if (selectedCount == 0) {
// return [[doc currentPage] layers]
[doc showMessage:'Please select at least one text layer']
var selectedGroups = flatten(selectedLayers)
if (selectedGroups.count() > 0) {
return selectedGroups
} else {
[doc showMessage:'Nothing selected']
return [NSArray new]
}
} else {
return doc.selectedLayersOfClass(MSTextLayer)
}
}

var flatten = function(array) {
var flatArray = [NSMutableArray new]

for (var i = 0; i < array.count(); i++) {
var item = [array objectAtIndex:i]
if (([item class] == MSLayerGroup || [item class] == MSArtboardGroup) && item.layers().count() > 0) {
[flatArray addObjectsFromArray:flatten(item.layers())]
} else {
if ([item class] == MSTextLayer) {
[flatArray addObject:item]
}
}
}
return flatArray
}

var moveLayer = function(layer) {
[layer adjustFrameToFit]
layer.setIsVisible(false)
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Comma, Fucker
Sketch plugin for text modifications.

Select one or multiple text layers to change the text. Following commands are available:
Select text layers, layer groups or artboards to change the text. Following commands are available:

* Change text to Lowercase, Uppercase, Title Case and Sentence Case
* Change three consecutive periods to ellipsis
Expand All @@ -11,8 +11,4 @@ Select one or multiple text layers to change the text. Following commands are av
* Replace all single line breaks with double line breaks (paragraph style)
* Show character and word counts

<img src="https://s3.amazonaws.com/f.cl.ly/items/1M2Z2D0l3t1T452J0t1M/,.png" alt="Comma, Fucker" width="337">

# Known issues

* Doesn’t change text when layers are grouped, i.e. one must directly select the text layer(s).
<img src="https://s3.amazonaws.com/f.cl.ly/items/1M2Z2D0l3t1T452J0t1M/,.png" alt="Comma, Fucker" width="337">

0 comments on commit a7aff86

Please sign in to comment.