Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added regex support to bulk remap #2511

Closed
wants to merge 3 commits into from

Conversation

xsu1010
Copy link

@xsu1010 xsu1010 commented Feb 23, 2024

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.
Screen.Recording.2024-02-22.at.21.17.40.mov

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? 😅

Copy link

changeset-bot bot commented Feb 23, 2024

🦋 Changeset detected

Latest commit: 5f380dc

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

@six7
Copy link
Collaborator

six7 commented Mar 5, 2024

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 six7 changed the base branch from main to release-139 April 26, 2024 15:43
@six7 six7 mentioned this pull request May 6, 2024
six7 added a commit that referenced this pull request May 6, 2024
This is just a rebase of
#2511 to release-139.
Merging as code is not mine and I'm merely approving.
@six7
Copy link
Collaborator

six7 commented May 6, 2024

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

@six7 six7 closed this May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants