Skip to content

Commit 17f24ef

Browse files
authored
Merge pull request #56 from thierryc/regex-fix-47
RegEx not working in Sketch 47 #55
2 parents ed3807c + 7edb05f commit 17f24ef

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
var FindAndReplace = function (context) {
77

88
var presets, userDefaults, document, selection, textToFind, textToReplace, searchScope, matchRegex, matchRegexStart, matchRegexEnd, matchRegexCase, REPLACE_ALL, READY_TO_SEARCH, CANCELLED, NOT_READY, itemsMatched;
9-
var version = '1.13';
9+
var version = '1.15';
1010

1111
// Initialise
1212
initialise(context);
@@ -107,11 +107,11 @@ var FindAndReplace = function (context) {
107107

108108
// Find text input
109109
userInterface.addTextLabelWithValue("Find");
110-
userInterface.addTextFieldWithValue(textToFind);
110+
userInterface.addTextFieldWithValue(userDefaults.textToFindOrigine || '');
111111

112112
// Replace with text input
113113
userInterface.addTextLabelWithValue("Replace with");
114-
userInterface.addTextFieldWithValue(textToReplace);
114+
userInterface.addTextFieldWithValue(userDefaults.textToReplaceOrigine || '');
115115

116116
// Scope
117117
userInterface.addTextLabelWithValue("Search scope");
@@ -136,7 +136,7 @@ var FindAndReplace = function (context) {
136136

137137
// Regex
138138
userInterface.addTextLabelWithValue("RegEx (for expert)")
139-
userInterface.addAccessoryView(createRadioButtons(["Yes", "No"], userDefaults.regex))
139+
userInterface.addAccessoryView(createRadioButtons(["No", "Yes"], userDefaults.regex))
140140

141141
// Replace and cancel buttons
142142
userInterface.addButtonWithTitle('Replace All');
@@ -211,6 +211,9 @@ var FindAndReplace = function (context) {
211211
textToReplace = modal.viewAtIndex(3).stringValue();
212212
searchScope = [[[modal viewAtIndex: 5] selectedCell] tag];
213213

214+
userDefaults.textToFindOrigine = textToFind;
215+
userDefaults.textToReplaceOrigine = textToReplace;
216+
214217
userDefaults.caseSensitivity = [[[modal viewAtIndex: 7] selectedCell] tag];
215218
userDefaults.caseReplace = [[[modal viewAtIndex: 9] selectedCell] tag];
216219
userDefaults.matchWhere = [[[modal viewAtIndex: 11] selectedCell] tag];
@@ -223,15 +226,11 @@ var FindAndReplace = function (context) {
223226

224227
// Make sure we have text to find
225228
if (textToFind != "") {
226-
227229
// Yeah, ready to go
228230
result = READY_TO_SEARCH;
229-
230231
} else {
231-
232232
// Need something in find and replace
233233
result = NOT_READY;
234-
235234
}
236235

237236
} else {
@@ -255,14 +254,13 @@ var FindAndReplace = function (context) {
255254

256255
// Build the regex to match on, based on the user options
257256
var regexString = matchRegexStart[userDefaults.matchWhole][userDefaults.matchWhere] + cleanSearch(textToFind) + matchRegexEnd[userDefaults.matchWhole][userDefaults.matchWhere];
258-
if (!userDefaults.regex) {
257+
258+
if (!userDefaults.regex) { // 0
259259
matchRegex = new RegExp(regexString, matchRegexCase[userDefaults.caseSensitivity]);
260-
} else {
260+
} else { // 1
261261
matchRegex = new RegExp(textToFind, matchRegexCase[userDefaults.caseSensitivity]);
262262
}
263263

264-
265-
266264
// Determine the scope and launch the search accordingly
267265
switch (searchScope) {
268266

@@ -335,13 +333,13 @@ var FindAndReplace = function (context) {
335333

336334
function replaceValue(sourceString, replaceString) {
337335
var newStringValue;
338-
if (userDefaults.regex == 1) {
336+
if (!userDefaults.regex) { // 0
339337
newStringValue = sourceString.replace(matchRegex,
340338
function(eachMatch){
341339
return doIntelligentReplace(eachMatch, replaceString);
342340
}
343341
);
344-
} else {
342+
} else { // 1
345343
newStringValue = sourceString.replace(matchRegex, replaceString);
346344
}
347345
return newStringValue

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11

22
![Find and Replace for Sketch](https://raw.githubusercontent.com/thierryc/Sketch-Find-And-Replace/master/Ressources/logo-256.png)
3-
43
# Find and Replace for Sketch
54

65
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.
76

87
Now works with symbol overrides. 🎉
98

9+
Ready for Sketch 47.
10+
1011
![Find and Replace dialog](./Screenshots/screenshot.png)
1112

1213
## Installation
1314

14-
Download and unzip, then double-click on the `Find and Replace.sketchplugin` file.
15+
Download and unzip, then double-click on the `Find and Replace.sketchplugin` file.
1516
Sketch will copy it to the plugins folder and install it automatically.
1617

17-
### Install with Sketch Runner
18+
### Install with Sketch Runner
1819

1920
With Sketch Runner, just go to the `install` command and search for `Find and Replace`. Runner allows you to manage plugins and do much more to speed up your workflow in Sketch. [Download Runner here](http://www.sketchrunner.com).
2021

@@ -89,7 +90,7 @@ Get the Regex Power ! ⚡️
8990

9091
### "John Smith" to "Smith John"
9192

92-
Find
93+
Find
9394
```
9495
(\w+)\s+(\w+)
9596
```
@@ -100,9 +101,9 @@ $2 $1
100101
```
101102

102103
Result: Smith John.
103-
104104

105-
#### Replace all double spaces
105+
106+
#### Replace all double spaces
106107

107108
Find
108109
```
@@ -111,12 +112,12 @@ Find
111112
```
112113

113114
Replace with
114-
```
115+
```
115116
(one space)
116117
117118
```
118119

119-
Follow me on twitter for more tips.
120+
Follow me on twitter for more tips.
120121

121122
https://twitter.com/Autre_planete
122123

appcast.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
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.15</title>
10+
<description>
11+
<![CDATA[
12+
<ul>
13+
<li>Fix regex for sktech 47</li>
14+
<li>Save find and replace string</li>
15+
</ul>
16+
]]>
17+
</description>
18+
<pubDate>Wed Nov 22 12:00:00 EDT 2017</pubDate>
19+
<enclosure url="https://github.com/thierryc/Sketch-Find-And-Replace/archive/1.14.zip" type="application/octet-stream" sparkle:version="1.15"/>
20+
</item>
821
<item>
922
<title>1.14</title>
1023
<description>

0 commit comments

Comments
 (0)