Skip to content

Fix token set folder drag-reorder scrambling order when folders are expanded#3828

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-token-set-folder-drag-reordering
Draft

Fix token set folder drag-reorder scrambling order when folders are expanded#3828
Copilot wants to merge 2 commits intomainfrom
copilot/fix-token-set-folder-drag-reordering

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

Dragging a folder to reorder it produced a scrambled result when folders were expanded. The bug worsened when folder structures had been modified by renaming sets into existing folders.

Root Cause

ensureFolderIsTogether used a delta-based move that only repositioned direct children (parent === value.path). Grandchildren were left in place, becoming orphaned at the top of the list.

// Before drag: [common, common/base, common/heading-color, common/heading-color/mobile, global]
// After drag (old): [global, common/heading-color/mobile, common, common/base, common/heading-color]
//                            ^^^^^ orphaned grandchild                    ^^^^^ sub-folder at wrong position
// After drag (new): [global, common, common/base, common/heading-color, common/heading-color/mobile]

Changes

  • ensureFolderIsTogether: Replace delta-based child movement with a grouping approach — collect all descendants (parent === path or parent.startsWith(path + '/')), strip them from their scattered positions, and re-insert them contiguously after the folder in their original relative order.

  • findOrderableTargetIndexesInTokenSetTreeList: Fix startsWith(path)parent === path || startsWith(path + '/') to avoid falsely counting children of prefix-matching sibling folders (e.g. themes2 counted as child of themes).

  • TokenSetTree handleReorder: Same startsWith boundary fix in the collapsed-folder children lookup.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 31, 2026

🦋 Changeset detected

Latest commit: 7dcb0a8

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

@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Mar 31, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity . 16 duplication

Metric Results
Complexity 0
Duplication 16

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 31, 2026

⤵️ 📦 ✨ The artifact was successfully created! Want to test it? Download it here 👀 🎁

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 31, 2026

Commit SHA:ef1cbd26915901b63020f228e78e23567a09e5af

Test coverage results 🧪

Code coverage diff between base branch:main and head branch: copilot/fix-token-set-folder-drag-reordering 
Status File % Stmts % Branch % Funcs % Lines
🟢 total 63.03 (-0.01) 54.94 (0.02) 60.12 (0) 63.34 (0)
🔴 packages/tokens-studio-for-figma/src/app/components/TokenSetTree.tsx 64.55 (0) 41.02 (-1.08) 62.06 (0) 64.7 (0)
🟢 packages/tokens-studio-for-figma/src/utils/dragDropOrder/ensureFolderIsTogether.ts 87.5 (-12.5) 75 (25) 100 (0) 90.9 (-9.1)

Copilot AI changed the title [WIP] Fix token set folder drag-reorder issue with expanded folders Fix token set folder drag-reorder scrambling order when folders are expanded Mar 31, 2026
Copilot AI requested a review from akshay-gupta7 March 31, 2026 17:59
@github-actions
Copy link
Copy Markdown
Contributor

Commit SHA:ef1cbd26915901b63020f228e78e23567a09e5af
Current PR reduces the test coverage percentage by 1 for some tests

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.

Bug: Token set folder drag-reorder scrambles order when folders are expanded

2 participants