diff --git a/Find And Replace.sketchplugin/Contents/Sketch/FindAndReplace.sketchscript b/Find And Replace.sketchplugin/Contents/Sketch/FindAndReplace.sketchscript index e9ac485..86de3f8 100644 --- a/Find And Replace.sketchplugin/Contents/Sketch/FindAndReplace.sketchscript +++ b/Find And Replace.sketchplugin/Contents/Sketch/FindAndReplace.sketchscript @@ -6,7 +6,7 @@ var FindAndReplace = function (context) { var presets, userDefaults, document, selection, textToFind, textToReplace, searchScope, matchRegex, matchRegexStart, matchRegexEnd, matchRegexCase, REPLACE_ALL, READY_TO_SEARCH, CANCELLED, NOT_READY, itemsMatched; - var version = '1.13'; + var version = '1.15'; // Initialise initialise(context); @@ -107,11 +107,11 @@ var FindAndReplace = function (context) { // Find text input userInterface.addTextLabelWithValue("Find"); - userInterface.addTextFieldWithValue(textToFind); + userInterface.addTextFieldWithValue(userDefaults.textToFindOrigine || ''); // Replace with text input userInterface.addTextLabelWithValue("Replace with"); - userInterface.addTextFieldWithValue(textToReplace); + userInterface.addTextFieldWithValue(userDefaults.textToReplaceOrigine || ''); // Scope userInterface.addTextLabelWithValue("Search scope"); @@ -136,7 +136,7 @@ var FindAndReplace = function (context) { // Regex userInterface.addTextLabelWithValue("RegEx (for expert)") - userInterface.addAccessoryView(createRadioButtons(["Yes", "No"], userDefaults.regex)) + userInterface.addAccessoryView(createRadioButtons(["No", "Yes"], userDefaults.regex)) // Replace and cancel buttons userInterface.addButtonWithTitle('Replace All'); @@ -211,6 +211,9 @@ var FindAndReplace = function (context) { textToReplace = modal.viewAtIndex(3).stringValue(); searchScope = [[[modal viewAtIndex: 5] selectedCell] tag]; + userDefaults.textToFindOrigine = textToFind; + userDefaults.textToReplaceOrigine = textToReplace; + userDefaults.caseSensitivity = [[[modal viewAtIndex: 7] selectedCell] tag]; userDefaults.caseReplace = [[[modal viewAtIndex: 9] selectedCell] tag]; userDefaults.matchWhere = [[[modal viewAtIndex: 11] selectedCell] tag]; @@ -223,15 +226,11 @@ var FindAndReplace = function (context) { // Make sure we have text to find if (textToFind != "") { - // Yeah, ready to go result = READY_TO_SEARCH; - } else { - // Need something in find and replace result = NOT_READY; - } } else { @@ -255,14 +254,13 @@ var FindAndReplace = function (context) { // Build the regex to match on, based on the user options var regexString = matchRegexStart[userDefaults.matchWhole][userDefaults.matchWhere] + cleanSearch(textToFind) + matchRegexEnd[userDefaults.matchWhole][userDefaults.matchWhere]; - if (!userDefaults.regex) { + + if (!userDefaults.regex) { // 0 matchRegex = new RegExp(regexString, matchRegexCase[userDefaults.caseSensitivity]); - } else { + } else { // 1 matchRegex = new RegExp(textToFind, matchRegexCase[userDefaults.caseSensitivity]); } - - // Determine the scope and launch the search accordingly switch (searchScope) { @@ -335,13 +333,13 @@ var FindAndReplace = function (context) { function replaceValue(sourceString, replaceString) { var newStringValue; - if (userDefaults.regex == 1) { + if (!userDefaults.regex) { // 0 newStringValue = sourceString.replace(matchRegex, function(eachMatch){ return doIntelligentReplace(eachMatch, replaceString); } ); - } else { + } else { // 1 newStringValue = sourceString.replace(matchRegex, replaceString); } return newStringValue diff --git a/README.md b/README.md index 46a5495..103b106 100755 --- a/README.md +++ b/README.md @@ -1,20 +1,21 @@ ![Find and Replace for Sketch](https://raw.githubusercontent.com/thierryc/Sketch-Find-And-Replace/master/Ressources/logo-256.png) - # Find and Replace for Sketch 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. Now works with symbol overrides. 🎉 +Ready for Sketch 47. + ![Find and Replace dialog](./Screenshots/screenshot.png) ## Installation -Download and unzip, then double-click on the `Find and Replace.sketchplugin` file. +Download and unzip, then double-click on the `Find and Replace.sketchplugin` file. Sketch will copy it to the plugins folder and install it automatically. -### Install with Sketch Runner +### Install with Sketch Runner 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). @@ -89,7 +90,7 @@ Get the Regex Power ! ⚡️ ### "John Smith" to "Smith John" -Find +Find ``` (\w+)\s+(\w+) ``` @@ -100,9 +101,9 @@ $2 $1 ``` Result: Smith John. - -#### Replace all double spaces + +#### Replace all double spaces Find ``` @@ -111,12 +112,12 @@ Find ``` Replace with -``` +``` (one space) ``` -Follow me on twitter for more tips. +Follow me on twitter for more tips. https://twitter.com/Autre_planete diff --git a/appcast.xml b/appcast.xml index bc4a44b..d8fec05 100644 --- a/appcast.xml +++ b/appcast.xml @@ -5,6 +5,19 @@ https://raw.githubusercontent.com/thierryc/Sketch-Find-And-Replace/master/appcast.xml 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. en + + 1.15 + + +
  • Fix regex for sktech 47
  • +
  • Save find and replace string
  • + + ]]> +
    + Wed Nov 22 12:00:00 EDT 2017 + +
    1.14