-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial working version * Use the actual length * Get color from global scheme * Use JB yellow * Make the test dynamic * Some cleanup * Sort the indexes before applying the highlight * Add license * Line up * Rename hex function * Use indexes instead of a for loop * Just handle each letter one by one * Add settings to control highlight (only for styled) and fix tests * Use lazy loading to compute the start tag string * Make colorAsHex private * Create a config class to store the style tags instead of a lazy var * Remove extra print * Add change notes and increment version * Ensure that highlight option is properly set at start
- Loading branch information
Showing
13 changed files
with
217 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
MIT License | ||
Copyright (c) 2024 Mitja Leino | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
package com.mituuz.fuzzier.settings | ||
|
||
import com.intellij.ui.JBColor | ||
import java.awt.Color | ||
|
||
object FuzzierConfiguration { | ||
var startStyleTag = createStartStyleTag() | ||
const val END_STYLE_TAG: String = "</font>" | ||
|
||
private fun createStartStyleTag(): String { | ||
val color = JBColor.YELLOW | ||
return "<font style='background-color: ${colorAsHex(color)};'>" | ||
} | ||
|
||
@Suppress("unused") // TODO: Update the base color for highlights | ||
private fun updateStartStyleTag(colorAsHex: String) { | ||
this.startStyleTag = "<font style='background-color: $colorAsHex;'>" | ||
} | ||
|
||
private fun colorAsHex(color: Color): String { | ||
return String.format("#%02x%02x%02x", color.red, color.green, color.blue) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/test/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
MIT License | ||
Copyright (c) 2024 Mitja Leino | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
package com.mituuz.fuzzier.entities | ||
|
||
import com.intellij.testFramework.TestApplicationManager | ||
import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FuzzyScore | ||
import com.mituuz.fuzzier.settings.FuzzierConfiguration.END_STYLE_TAG | ||
import com.mituuz.fuzzier.settings.FuzzierConfiguration.startStyleTag | ||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.Test | ||
|
||
class FuzzyMatchContainerTest { | ||
@Suppress("unused") | ||
private val testManager = TestApplicationManager.getInstance() | ||
|
||
@Test | ||
fun `Test highlight indexing simple case`() { | ||
val score = FuzzyScore() | ||
score.highlightCharacters.add(0) | ||
score.highlightCharacters.add(4) | ||
val container = FuzzyMatchContainer(score, "", "Hello") | ||
val res = container.highlight(container.filename) | ||
assertEquals("${startStyleTag}H${END_STYLE_TAG}ell${startStyleTag}o$END_STYLE_TAG", res) | ||
} | ||
|
||
@Test | ||
fun `Test highlight indexing complex case`() { | ||
val score = FuzzyScore() | ||
score.highlightCharacters.add(0) // f | ||
score.highlightCharacters.add(1) // u | ||
score.highlightCharacters.add(2) // z | ||
score.highlightCharacters.add(3) // z | ||
score.highlightCharacters.add(15) // i | ||
score.highlightCharacters.add(17) // e | ||
score.highlightCharacters.add(18) // r | ||
|
||
val container = FuzzyMatchContainer(score, "", "FuzzyMatchContainerTest.kt") | ||
val res = container.highlight(container.filename) | ||
val sb = StringBuilder() | ||
|
||
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(startStyleTag, "i", END_STYLE_TAG) | ||
sb.append("n") | ||
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) { | ||
assertEquals(sb.toString()[i], res[i]) | ||
i++ | ||
} | ||
} | ||
} |
Oops, something went wrong.