figma-plugin icon indicating copy to clipboard operation
figma-plugin copied to clipboard

feat: added regex support to bulk remap

Open xsu1010 opened this issue 2 years ago • 2 comments

Why does this PR exist?

The Bulk Remap feature is incredibly useful, as it saves a ton of time and work when renaming multiple tokens. By adding regex support to it, one can provide more precise patterns to the token search, allowing them to bulk remap tokens even faster.

What does this pull request do?

  • bulkRemapTokens.ts
    • Added support for regex
    • Added test for regex search

Testing this change

  1. Select multiple layers.
  2. Use the bulk remap feature and enter a regular expression that matches a portion of the tokens in those layers.
  3. Enter a value to change that portion to. Note how only the portion that matches the regex will change.

https://github.com/tokens-studio/figma-plugin/assets/25635678/cf2bb7a2-7f0c-4372-9147-8fe4701f6be3

Additional Notes (if any)

  • Although I changed how the code tests the token for pattern instead of oldName, this does not affect the current way of searching for a normal string, as normal strings are also valid regex.
  • When creating the pattern const, it checks to see if the string passed is already a regex with slashes, and if so, ~~it strips the first and last slashes — if the slashes remained, then the matches wouldn't be the same anymore, as it would actually search for the slashes.~~ it uses that regex pattern with the given flags, if any.
    • However, I also made it so that the user doesn't need to pass slashes to use a regex — if there are no slashes, it just uses that pattern with a global flag (matches all occurrences of that pattern in the token), as you can see in the video above.
    • When doing this, I thought that maybe you'd prefer to enforce the usage the slashes if the user is trying to include regex in the search. Which one would you prefer? 😅

xsu1010 avatar Feb 23 '24 12:02 xsu1010

🦋 Changeset detected

Latest commit: 5f380dc00c64aeb61339e578a37f581fed4d7793

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tokens-studio/figma-plugin Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Feb 23 '24 12:02 changeset-bot[bot]

Thank you for this! We're currently working on a dedicated branch for the upcoming 2.0 release which I'll rebase this PR on, which shouldn't lead to any conflicts given we've not changed much in this area of the plugin.

six7 avatar Mar 05 '24 06:03 six7

Closing as we merged the other rebased PR 👍 Thank you!!

six7 avatar May 06 '24 07:05 six7