diff --git a/src/main/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainer.kt b/src/main/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainer.kt index 8e85043..ca39969 100644 --- a/src/main/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainer.kt +++ b/src/main/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainer.kt @@ -29,12 +29,16 @@ import com.mituuz.fuzzier.settings.FuzzierSettingsService import java.awt.Color class FuzzyMatchContainer(val score: FuzzyScore, var filePath: String, var filename: String, private var module: String = "") { - private val color = JBColor.YELLOW - private val startStyleTag: String = "" - private val endStyleTag: String = "" private var initialPath: String? = null companion object { + const val END_STYLE_TAG: String = "" + + val startStyleTag: String by lazy { + val color = JBColor.YELLOW + "" + } + fun createOrderedContainer(order: Int, filePath: String, initialPath:String, filename: String): FuzzyMatchContainer { val fuzzyScore = FuzzyScore() fuzzyScore.filenameScore = order @@ -72,8 +76,8 @@ class FuzzyMatchContainer(val score: FuzzyScore, var filePath: String, var filen if (i < source.length) { stringBuilder.insert(i + offset, startStyleTag) offset += startStyleTag.length - stringBuilder.insert(i + offset + 1, endStyleTag) - offset += endStyleTag.length + stringBuilder.insert(i + offset + 1, END_STYLE_TAG) + offset += END_STYLE_TAG.length } } return stringBuilder.toString() diff --git a/src/test/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainerTest.kt b/src/test/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainerTest.kt index cd487e4..ed6ae39 100644 --- a/src/test/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainerTest.kt +++ b/src/test/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainerTest.kt @@ -24,25 +24,15 @@ SOFTWARE. package com.mituuz.fuzzier.entities import com.intellij.testFramework.TestApplicationManager -import com.intellij.ui.JBColor -import com.mituuz.fuzzier.entities.FuzzyMatchContainer.Companion.colorAsHex +import com.mituuz.fuzzier.entities.FuzzyMatchContainer.Companion.END_STYLE_TAG +import com.mituuz.fuzzier.entities.FuzzyMatchContainer.Companion.startStyleTag import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FuzzyScore import org.junit.jupiter.api.Assertions.* -import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test class FuzzyMatchContainerTest { @Suppress("unused") private val testManager = TestApplicationManager.getInstance() - private lateinit var yellow: String - private lateinit var startTag: String - private var endTag = "" - - @BeforeEach - fun setUp() { - yellow = colorAsHex(JBColor.YELLOW) - startTag = "" - } @Test fun `Test highlight indexing simple case`() { @@ -51,7 +41,7 @@ class FuzzyMatchContainerTest { score.highlightCharacters.add(4) val container = FuzzyMatchContainer(score, "", "Hello") val res = container.highlight(container.filename) - assertEquals("${startTag}H${endTag}ell${startTag}o$endTag", res) + assertEquals("${startStyleTag}H${END_STYLE_TAG}ell${startStyleTag}o$END_STYLE_TAG", res) } @Test @@ -66,19 +56,18 @@ class FuzzyMatchContainerTest { score.highlightCharacters.add(18) // r val container = FuzzyMatchContainer(score, "", "FuzzyMatchContainerTest.kt") - yellow = colorAsHex(JBColor.YELLOW) val res = container.highlight(container.filename) val sb = StringBuilder() - sb.append(startTag, "F", endTag) - sb.append(startTag, "u", endTag) - sb.append(startTag, "z", endTag) - sb.append(startTag, "z", endTag) + sb.append(startStyleTag, "F", END_STYLE_TAG) + sb.append(startStyleTag, "u", END_STYLE_TAG) + sb.append(startStyleTag, "z", END_STYLE_TAG) + sb.append(startStyleTag, "z", END_STYLE_TAG) sb.append("yMatchConta") - sb.append(startTag, "i", endTag) + sb.append(startStyleTag, "i", END_STYLE_TAG) sb.append("n") - sb.append(startTag, "e", endTag) - sb.append(startTag, "r", endTag) + sb.append(startStyleTag, "e", END_STYLE_TAG) + sb.append(startStyleTag, "r", END_STYLE_TAG) sb.append("Test.kt") var i = 0 while (i < res.length) {