Skip to content

Commit 427662d

Browse files
authored
Merge pull request #49 from thierryc/replaceTextPreservingAttributeRanges
ReplaceTextPreservingAttributeRanges #48
2 parents ecbdfd1 + 0f0919e commit 427662d

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var FindAndReplace = function (context) {
1717
function initialise(context) {
1818

1919
presets = {
20-
caseSensitivity: 0, // Off by default
20+
caseSensitivity: 0, // on by default
2121
caseReplace: 0, // Intelligent by default
2222
matchWhere: 1, // Anywhere by default
2323
matchWhole: 1, // Not whole words by default
@@ -215,7 +215,7 @@ var FindAndReplace = function (context) {
215215
userDefaults.caseReplace = [[[modal viewAtIndex: 9] selectedCell] tag];
216216
userDefaults.matchWhere = [[[modal viewAtIndex: 11] selectedCell] tag];
217217
userDefaults.matchWhole = [[[modal viewAtIndex: 13] selectedCell] tag];
218-
userDefaults.regexString = [[[modal viewAtIndex: 15] selectedCell] tag];
218+
userDefaults.regex = [[[modal viewAtIndex: 15] selectedCell] tag];
219219

220220
saveDefaults(userDefaults);
221221

@@ -335,7 +335,7 @@ var FindAndReplace = function (context) {
335335

336336
function replaceValue(sourceString, replaceString) {
337337
var newStringValue;
338-
if (!userDefaults.regex) {
338+
if (userDefaults.regex == 1) {
339339
newStringValue = sourceString.replace(matchRegex,
340340
function(eachMatch){
341341
return doIntelligentReplace(eachMatch, replaceString);
@@ -360,7 +360,7 @@ var FindAndReplace = function (context) {
360360
// log(layer.stringValue());
361361
if (layer.stringValue() && layer.stringValue().trim().match(matchRegex)) {
362362
itemsMatched++;
363-
layer.setStringValue(replaceValue(layer.stringValue(), textToReplace));
363+
layer.replaceTextPreservingAttributeRanges(replaceValue(layer.stringValue(), textToReplace));
364364
layer.setName(layer.stringValue().trim().replace(/(\r\n|\n|\r)/gm," "));
365365
}
366366
break;
@@ -401,7 +401,6 @@ var FindAndReplace = function (context) {
401401
if(overrides[index].class().isSubclassOfClass_(NSMutableDictionary.class()) ) {
402402
overrides[index] = searchInSymbolsInception(overrides[index]);
403403
} else if(overrides[index].class().isSubclassOfClass_(NSString.class()) ) {
404-
// log(overrides[index]);
405404
if (overrides[index] && overrides[index].trim() && overrides[index].trim().match(matchRegex)) {
406405
overrides[index] = replaceValue(overrides[index], textToReplace);
407406
}

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.11",
7+
"version": "1.12",
88
"identifier": "cx.ap.sketch-find-and-replace",
99
"icon" : "runner-icon.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: 13 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.12</title>
10+
<description>
11+
<![CDATA[
12+
<ul>
13+
<li>Fix bug and add version at the end of the description</li>
14+
</ul>
15+
]]>
16+
</description>
17+
<pubDate>Mon Oct 16 07:38:00 EDT 2017</pubDate>
18+
<enclosure url="https://github.com/thierryc/Sketch-Find-And-Replace/archive/1.12.zip" type="application/octet-stream" sparkle:version="1.12"/>
19+
</item>
820
<item>
921
<title>1.11</title>
1022
<description>
@@ -17,6 +29,7 @@
1729
<pubDate>Tue Jul 17 07:38:00 EDT 2017</pubDate>
1830
<enclosure url="https://github.com/thierryc/Sketch-Find-And-Replace/archive/1.11.zip" type="application/octet-stream" sparkle:version="1.11"/>
1931
</item>
32+
<item>
2033
<title>1.10</title>
2134
<description>
2235
<![CDATA[

0 commit comments

Comments
 (0)