@@ -313,6 +313,7 @@ var FindAndReplace = function (context) {
313313
314314    // Intelligent replace which attempts to match case if possible
315315    function doIntelligentReplace(replaceThis, replaceWith) {
316+         log(replaceThis + ' -- ' + replaceWith);
316317        var replacement = replaceWith;
317318        if (userDefaults.caseReplace == 1) {
318319            if (replaceThis.charAt(0) == replaceThis.charAt(0).toLowerCase()) {
@@ -331,6 +332,19 @@ var FindAndReplace = function (context) {
331332        return replacement;
332333    }
333334
335+     function replaceValue(sourceString, replaceString) {
336+       var newStringValue;
337+       if (!userDefaults.regex) {
338+         newStringValue = sourceString.replace(matchRegex,
339+           function(eachMatch){
340+             return doIntelligentReplace(eachMatch, replaceString);
341+           }
342+         );
343+       } else {
344+         newStringValue = sourceString.replace(matchRegex, replaceString);
345+       }
346+       return newStringValue
347+     }
334348
335349    // Do the actual search within the specified layer.  Recursive to drill down into sublayers.
336350
@@ -344,7 +358,7 @@ var FindAndReplace = function (context) {
344358            case MSTextLayer:
345359                if ([layer stringValue].trim().match(matchRegex)) {
346360                    itemsMatched++;
347-                     layer.setStringValue(layer.stringValue().replace(matchRegex,function(eachMatch){return doIntelligentReplace(eachMatch,  textToReplace);} ));
361+                     layer.setStringValue(replaceValue( layer.stringValue(),  textToReplace));
348362                    layer.setName(layer.stringValue().trim().replace(/(\r\n|\n|\r)/gm," "));
349363                }
350364                break;
@@ -389,11 +403,7 @@ var FindAndReplace = function (context) {
389403              overrides[index] = searchInSymbolsInception(overrides[index]);
390404          } else if(overrides[index].class().isSubclassOfClass_(NSString.class()) ) {
391405            if (overrides[index].trim() && overrides[index].trim().match(matchRegex)) {
392-               overrides[index] = overrides[index].replace(matchRegex,
393-                 function(eachMatch){
394-                   return doIntelligentReplace(eachMatch, textToReplace);
395-                 }
396-               );
406+               overrides[index] = replaceValue(overrides[index], textToReplace);
397407            }
398408          }
399409        }
@@ -408,11 +418,7 @@ var FindAndReplace = function (context) {
408418            overrides[index] = searchInSymbolsInception(overrides[index]);
409419        } else if(overrides[index].class().isSubclassOfClass_(NSString.class()) ) {
410420          if (overrides[index].trim() && overrides[index].trim().match(matchRegex)) {
411-             overrides[index] = overrides[index].replace(matchRegex,
412-               function(eachMatch) {
413-                 return doIntelligentReplace(eachMatch, textToReplace);
414-               }
415-             );
421+             overrides[index] = replaceValue(overrides[index], textToReplace);
416422          }
417423        }
418424      }
0 commit comments