Skip to content

Commit 932f5fb

Browse files
committed
Add Replace the text label option #61
1 parent d4538dc commit 932f5fb

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

Find And Replace.sketchplugin/Contents/Sketch/FindAndReplace.sketchscript

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
var FindAndReplace = function (context) {
1010

1111
var presets, userDefaults, document, selection, textToFind, textToReplace, searchScope, matchRegex, matchRegexStart, matchRegexEnd, matchRegexCase, REPLACE_ALL, READY_TO_SEARCH, CANCELLED, NOT_READY, itemsMatched;
12-
var version = '1.22';
12+
var version = '1.24';
1313

1414
// Initialise
1515
initialise(context);
@@ -24,7 +24,8 @@ var FindAndReplace = function (context) {
2424
caseReplace: 0, // Intelligent by default
2525
matchWhere: 1, // Anywhere by default
2626
matchWhole: 1, // Not whole words by default
27-
regex: 1 // Not active
27+
regex: 1, // Not active
28+
renameLabel: 1 // rename the label
2829
}
2930

3031
userDefaults = initDefaults("cx.ap.sketch-find-and-replace", presets);
@@ -139,6 +140,10 @@ var FindAndReplace = function (context) {
139140
userInterface.addTextLabelWithValue("RegEx (for expert)")
140141
userInterface.addAccessoryView(createRadioButtons(["No", "Yes"], userDefaults.regex))
141142

143+
// Replace text label
144+
userInterface.addTextLabelWithValue("Replace text label (default “Yes”)")
145+
userInterface.addAccessoryView(createRadioButtons(["No", "Yes"], userDefaults.renameLabel))
146+
142147
// Replace and cancel buttons
143148
userInterface.addButtonWithTitle('Replace All');
144149
userInterface.addButtonWithTitle('Cancel');
@@ -219,10 +224,18 @@ var FindAndReplace = function (context) {
219224
userDefaults.matchWhere = [[[modal viewAtIndex: 11] selectedCell] tag];
220225
userDefaults.matchWhole = [[[modal viewAtIndex: 13] selectedCell] tag];
221226
userDefaults.regex = [[[modal viewAtIndex: 15] selectedCell] tag];
227+
userDefaults.renameLabel = [[[modal viewAtIndex: 17] selectedCell] tag];
222228

223229
saveDefaults(userDefaults);
224230

225-
log ("Scope " + searchScope + " - Case " + userDefaults.caseSensitivity + " - Replace " + userDefaults.caseReplace + " - Where " + userDefaults.matchWhere + " - Whole " + userDefaults.matchWhole + " - regex " + userDefaults.regex);
231+
log ("Scope " + searchScope
232+
+ " - Case " + userDefaults.caseSensitivity
233+
+ " - Replace " + userDefaults.caseReplace
234+
+ " - Where " + userDefaults.matchWhere
235+
+ " - Whole " + userDefaults.matchWhole
236+
+ " - regex " + userDefaults.regex
237+
+ " - renameLabel " + userDefaults.renameLabel
238+
);
226239

227240
// Make sure we have text to find
228241
if (textToFind != "") {
@@ -362,7 +375,9 @@ var FindAndReplace = function (context) {
362375
if (layer.stringValue() && layer.stringValue().trim().match(matchRegex)) {
363376
itemsMatched++;
364377
layer.replaceTextPreservingAttributeRanges(replaceValue(layer.stringValue(), textToReplace));
365-
layer.setName(layer.stringValue().trim().replace(/(\r\n|\n|\r)/gm," "));
378+
if (userDefaults.renameLabel == 1) {
379+
layer.setName(layer.stringValue().trim().replace(/(\r\n|\n|\r)/gm," "));
380+
}
366381
}
367382
break;
368383

Find And Replace.sketchplugin/Contents/Sketch/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"author": "Martin Steven and Thierry Charbonnel",
55
"authorEmail" : "thierry.charbonnel@autreplanete.com",
66
"homepage": "https://github.com/thierryc/Sketch-Find-And-Replace/",
7-
"version": "1.23",
7+
"version": "1.24",
88
"identifier": "cx.ap.sketch-find-and-replace",
99
"icon" : "sketch-find-and-replace.png",
1010
"updateURL": "https://raw.githubusercontent.com/thierryc/Sketch-Find-And-Replace/master/Find%20And%20Replace.sketchplugin/Contents/Sketch/manifest.json",

appcast.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
<link>https://raw.githubusercontent.com/thierryc/Sketch-Find-And-Replace/master/appcast.xml</link>
66
<description>Finds text in selected layer(s) and all layers contained within - and replaces it with different text. Features partial, case sensitive and full-document matching.</description>
77
<language>en</language>
8+
<item>
9+
<title>1.24</title>
10+
<description>
11+
<![CDATA[
12+
<ul>
13+
<li>Add icons</li>
14+
</ul>
15+
]]>
16+
</description>
17+
<pubDate>Sun May 3 18:30:00 EDT 2018</pubDate>
18+
<enclosure url="https://github.com/thierryc/Sketch-Find-And-Replace/archive/1.24.zip" type="application/octet-stream" sparkle:version="1.24"/>
19+
</item>
820
<item>
921
<title>1.23</title>
1022
<description>

0 commit comments

Comments
 (0)