diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dcc5e2..73c99f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,6 @@ ## [Unreleased] -## [2.0.4] +## [2.0.5] ### Added -- Performance enhancement: tasks now run in background threads with full progress indication +- Improved handling of double variants when using dark: such as `dark:hover:bg-red-500` diff --git a/gradle.properties b/gradle.properties index 9a6f89d..cd5be40 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ pluginGroup = com.github.walrussoup.tailwindformatternext pluginName = tailwind-formatter-next # SemVer format -> https://semver.org -pluginVersion = 2.0.4 +pluginVersion = 2.0.5 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html pluginSinceBuild = 213 diff --git a/src/main/kotlin/com/github/walrussoup/tailwindformatternext/support/TailwindSorter.kt b/src/main/kotlin/com/github/walrussoup/tailwindformatternext/support/TailwindSorter.kt index c82bf2b..ef983d4 100644 --- a/src/main/kotlin/com/github/walrussoup/tailwindformatternext/support/TailwindSorter.kt +++ b/src/main/kotlin/com/github/walrussoup/tailwindformatternext/support/TailwindSorter.kt @@ -102,6 +102,14 @@ class TailwindSorter(classOrder: List, isCustomConfiguration: Boolean) : if(variantApplied.contains("[")) { return (variantsStartAt + variantOrder.size * classOrder.size + calculateProperOrder(classApplied)); } + // split by : to see if there are two variants on the left + if (variantApplied.split(":").count() >= 2) { + // if there are two variants, split it by two and add them together to calculate the proper, newly formed offset of both variants + // This is 100% a guess where they should naturally be located + val firstVariant = variantApplied.split(":")[0] + val secondVariant = variantApplied.split(":")[1] + return (variantsStartAt + (variantOrder.indexOf(firstVariant) + variantOrder.indexOf(secondVariant)) * classOrder.size + calculateProperOrder(classApplied)) + } // if its a variant with an existing order in the spec, keep that return (variantsStartAt + variantOrder.indexOf(variantApplied) * classOrder.size + calculateProperOrder(classApplied)) } diff --git a/src/test/kotlin/com/github/walrussoup/tailwindformatternext/SorterTest.kt b/src/test/kotlin/com/github/walrussoup/tailwindformatternext/SorterTest.kt index c269e60..fa6b987 100644 --- a/src/test/kotlin/com/github/walrussoup/tailwindformatternext/SorterTest.kt +++ b/src/test/kotlin/com/github/walrussoup/tailwindformatternext/SorterTest.kt @@ -130,4 +130,18 @@ class SorterTest : BasePlatformTestCase() { assertEquals(expectedOrder, it) } } + + fun testCanSortDoubleVariants() { + val outOfOrderVariants = "text-red-500 dark:disabled:bg-red-200 dark:hover:bg-red-500 font-semibold font-serif dark:font-thin dark:text-red-200 bg-red-500"; + val expectedOrder = "bg-red-500 font-serif font-semibold text-red-500 dark:font-thin dark:text-red-200 dark:hover:bg-red-500 dark:disabled:bg-red-200"; + + val utility = TailwindUtility(); + utility.loadDefaultClassOrder() + + val sorter = TailwindSorter(utility.classOrder, false) + val classes: List = outOfOrderVariants.split(" ").toList(); + classes.sortedWith(sorter).joinToString(" ").let { + assertEquals(expectedOrder, it) + } + } }