99var 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
0 commit comments