Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 27, 2025

This PR adds figma.commitUndo() calls at key points where tokens are applied to or removed from Figma layers, enabling users to use Figma's native undo (Cmd/Ctrl+Z) to revert token operations in logical chunks.

Problem

Previously, when users applied or removed design tokens, there were no undo points created in Figma's history. This meant that using Figma's native undo would either not work or would undo unrelated operations, making it difficult to experiment with tokens or correct mistakes.

Solution

Added strategic figma.commitUndo() calls before major token operations:

  • Token Application: Before applying token values to selected nodes
  • Token Removal: Before removing tokens by value or setting "none" values
  • Bulk Operations: Before remapping tokens or bulk remapping operations
  • Style Swapping: Before swapping styles between themes
  • Living Documentation: Before applying tokens to documentation components
  • Node Data Updates: Before updating node data with token references

Implementation Details

All figma.commitUndo() calls are guarded with proper checks:

if (typeof figma !== 'undefined' && figma.commitUndo) {
  figma.commitUndo();
}

This ensures compatibility with test environments where the Figma API may not be available.

The implementation creates undo points at the right granularity level - one per high-level user action rather than per individual property or node, preventing excessive undo points that would make the undo history difficult to navigate.

Files Modified

  • setValuesOnNode.ts - Main token application function
  • asyncMessageHandlers/removeTokensByValue.ts - Token removal operations
  • asyncMessageHandlers/update.ts - Bulk update operations
  • asyncMessageHandlers/setNodeData.ts - Node data updates
  • asyncMessageHandlers/swapStyles.ts - Style swapping between themes
  • asyncMessageHandlers/remapTokens.ts & bulkRemapTokens.ts - Token remapping
  • asyncMessageHandlers/setNoneValuesOnNode.ts - Setting none values
  • livingDocumentation/applyTokens.ts - Living documentation token application

Testing

  • All existing tests continue to pass
  • No security vulnerabilities introduced (verified with CodeQL)
  • Build successful with no compilation errors
  • Proper changeset created following repository guidelines

User Impact

Users can now:

  • Experiment with token applications knowing they can easily undo
  • Use familiar Figma undo shortcuts (Cmd/Ctrl+Z) to revert token operations
  • Navigate token application history in logical chunks
  • Recover from mistakes during bulk token operations

This significantly improves the user experience when working with design tokens in the plugin.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/tokens-studio/tokens-studio%2Ffigma-plugin/languages
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Lets add a few commitUndo points on various important actions where we are changing what we have applied on figma layers, or when updating values on layers. see https://developers.figma.com/docs/plugins/api/properties/figma-commitundo


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI assigned Copilot and six7 Sep 27, 2025
Copy link

changeset-bot bot commented Sep 27, 2025

🦋 Changeset detected

Latest commit: 107c189

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 Patch

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

Copilot AI and others added 2 commits September 27, 2025 08:34
Co-authored-by: six7 <4548309+six7@users.noreply.github.com>
Co-authored-by: six7 <4548309+six7@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Lets add a few commitUndo points on various important actions where we are changing what we have applied on figma layers, or when updating values on layers. see https://developers.figma.com/docs/plugins/api/properties/figma-commitundo Add figma.commitUndo() points for token operations Sep 27, 2025
@Copilot Copilot AI requested a review from six7 September 27, 2025 08:44
Copilot finished work on behalf of six7 September 27, 2025 08:44
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