Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ intellijPlatform {

changeNotes = """
<h2>Version $currentVersion</h2>
- Add option to ignore characters from search
- Update dependencies
""".trimIndent()

Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog
## Version 1.4.0
- Add option to ignore characters from search
- Update dependencies

## Version 1.3.0
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,13 @@ open class Fuzzier : FuzzyAction() {
stringEvaluator: StringEvaluator, listModel: DefaultListModel<FuzzyMatchContainer>,
searchString: String, task: Future<*>?
) {
val ss = FuzzierUtil.cleanSearchString(searchString, fuzzierSettingsService.state.ignoredCharacters)
runBlocking {
withContext(Dispatchers.IO) {
filesToIterate.forEach { iterationFile ->
if (task?.isCancelled == true) return@forEach
launch {
stringEvaluator.evaluateFile(iterationFile, listModel, searchString)
stringEvaluator.evaluateFile(iterationFile, listModel, ss)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/com/mituuz/fuzzier/FuzzyMover.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectori
import com.mituuz.fuzzier.components.SimpleFinderComponent
import com.mituuz.fuzzier.entities.FuzzyMatchContainer
import com.mituuz.fuzzier.entities.StringEvaluator
import com.mituuz.fuzzier.util.FuzzierUtil
import com.mituuz.fuzzier.util.FuzzierUtil.Companion.createDimensionKey
import org.apache.commons.lang3.StringUtils
import java.awt.Point
Expand Down Expand Up @@ -250,10 +251,11 @@ class FuzzyMover : FuzzyAction() {
private fun process(project: Project, stringEvaluator: StringEvaluator, searchString: String,
listModel: DefaultListModel<FuzzyMatchContainer>, task: Future<*>?) {
val moduleManager = ModuleManager.getInstance(project)
val ss = FuzzierUtil.cleanSearchString(searchString, fuzzierSettingsService.state.ignoredCharacters)
if (fuzzierSettingsService.state.isProject) {
processProject(project, stringEvaluator, searchString, listModel, task)
processProject(project, stringEvaluator, ss, listModel, task)
} else {
processModules(moduleManager, stringEvaluator, searchString, listModel, task)
processModules(moduleManager, stringEvaluator, ss, listModel, task)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBTextArea
import com.intellij.util.ui.FormBuilder
import com.intellij.openapi.ui.ComboBox
import com.intellij.ui.components.JBTextField
import com.mituuz.fuzzier.components.FuzzierSettingsComponent.SettingsComponent
import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FilenameType
import com.mituuz.fuzzier.settings.FuzzierSettingsService
Expand All @@ -54,6 +55,16 @@ class FuzzierSettingsComponent {
e.g. "kt" excludes all files/file paths that contain the "kt" string. (main.<strong>kt</strong>, <strong>kt</strong>lin.java)
""".trimIndent())

val ignoredCharacters = SettingsComponent(JBTextField(), "Ignored characters",
"""
Exclude characters from affecting the search. Any character added here will be skipped during the search.<br>
This could be useful for example when copy pasting similar file paths.<br>
<strong>Note! </strong>This is case insensitive, everything is considered as lowercase
<br><br>
e.g. "%" would transform a search string like "%%%kot%%lin" to "kotlin"
""".trimIndent(),
false)

val newTabSelect = SettingsComponent(JBCheckBox(), "Open files in a new tab")

val recentFileModeSelector = SettingsComponent(ComboBox<RecentFilesMode>(), "Show recent files on start", """
Expand Down Expand Up @@ -96,7 +107,7 @@ class FuzzierSettingsComponent {
<br>
<strong>file</strong> <i>(path/to/file)</i>
<br>
<strong>Note!</strong>This is more performance intensive, you should not use too high file list limit with this option.
<strong>Note! </strong>This is more performance intensive, you should not use too high file list limit with this option.
""".trimIndent(),
false)

Expand Down Expand Up @@ -196,6 +207,7 @@ class FuzzierSettingsComponent {
jPanel = FormBuilder.createFormBuilder()
.addComponent(JBLabel("<html><strong>General settings</strong></html>"))
.addComponent(exclusionSet)
.addComponent(ignoredCharacters)

.addSeparator()
.addComponent(newTabSelect)
Expand Down Expand Up @@ -309,6 +321,10 @@ class FuzzierSettingsComponent {
return component as JBTextArea
}

fun getJBTextField(): JBTextField {
return component as JBTextField
}

fun getCheckBox(): JBCheckBox {
return component as JBCheckBox
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ class TestBenchComponent : JPanel() {

private fun processProject(project: Project, stringEvaluator: StringEvaluator,
searchString: String, listModel: DefaultListModel<FuzzyMatchContainer>) {
val contentIterator = stringEvaluator.getContentIterator(project.name, searchString, listModel, null)
val ss = FuzzierUtil.cleanSearchString(searchString, liveSettingsComponent.ignoredCharacters.getJBTextField().text)
val contentIterator = stringEvaluator.getContentIterator(project.name, ss, listModel, null)

val scoreCalculator = stringEvaluator.scoreCalculator
scoreCalculator.setMultiMatch(liveSettingsComponent.multiMatchActive.getCheckBox().isSelected)
Expand All @@ -186,7 +187,8 @@ class TestBenchComponent : JPanel() {
searchString: String, listModel: DefaultListModel<FuzzyMatchContainer>) {
for (module in moduleManager.modules) {
val moduleFileIndex = module.rootManager.fileIndex
val contentIterator = stringEvaluator.getContentIterator(module.name, searchString, listModel, null)
val ss = FuzzierUtil.cleanSearchString(searchString, liveSettingsComponent.ignoredCharacters.getJBTextField().text)
val contentIterator = stringEvaluator.getContentIterator(module.name, ss, listModel, null)

val scoreCalculator = stringEvaluator.scoreCalculator
scoreCalculator.setMultiMatch(liveSettingsComponent.multiMatchActive.getCheckBox().isSelected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ScoreCalculator(searchString: String) {
private var matchWeightStreakModifier = settings.matchWeightStreakModifier
private var matchWeightPartialPath = settings.matchWeightPartialPath
private var matchWeightFilename = settings.matchWeightFilename
private var ignoredCharacters: Set<Char> = settings.ignoredCharacters.toSet()

var currentFilePath = ""
private var longestStreak: Int = 0
Expand Down Expand Up @@ -222,4 +223,8 @@ class ScoreCalculator(searchString: String) {
fun setTolerance(value: Int) {
tolerance = value
}

fun setIgnoredCharacters(characterString: String) {
ignoredCharacters = characterString.toSet()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class FuzzierSettingsConfigurable : Configurable {

val combinedString = state.exclusionSet.joinToString("\n")
component.exclusionSet.getJBTextArea().text = combinedString
component.ignoredCharacters.getJBTextField().text = state.ignoredCharacters
component.newTabSelect.getCheckBox().isSelected = state.newTab
component.recentFileModeSelector.getRecentFilesTypeComboBox().selectedIndex = state.recentFilesMode.ordinal
component.prioritizeShortDirs.getCheckBox().isSelected = state.prioritizeShorterDirPaths
Expand Down Expand Up @@ -71,6 +72,7 @@ class FuzzierSettingsConfigurable : Configurable {
.toSet()

return state.exclusionSet != newSet
|| state.ignoredCharacters != component.ignoredCharacters.getJBTextField().text
|| state.newTab != component.newTabSelect.getCheckBox().isSelected
|| state.recentFilesMode != component.recentFileModeSelector.getRecentFilesTypeComboBox().selectedItem
|| state.prioritizeShorterDirPaths != component.prioritizeShortDirs.getCheckBox().isSelected
Expand All @@ -97,6 +99,7 @@ class FuzzierSettingsConfigurable : Configurable {
.filter { it.isNotBlank() }
.toSet()
state.exclusionSet = newSet as MutableSet<String>
state.ignoredCharacters = component.ignoredCharacters.getJBTextField().text
state.newTab = component.newTabSelect.getCheckBox().isSelected
state.recentFilesMode = RecentFilesMode.entries.toTypedArray()[component.recentFileModeSelector.getRecentFilesTypeComboBox().selectedIndex]
state.prioritizeShorterDirPaths = component.prioritizeShortDirs.getCheckBox().isSelected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class FuzzierSettingsService : PersistentStateComponent<FuzzierSettingsService.S

var splitPosition: Int = 300
var exclusionSet: Set<String> = setOf("/.idea/*", "/.git/*", "/target/*", "/build/*", "/.gradle/*", "/.run/*")
var ignoredCharacters: String = ""
var newTab: Boolean = false
var prioritizeShorterDirPaths = true
var debouncePeriod: Int = 80
Expand Down
29 changes: 22 additions & 7 deletions src/main/kotlin/com/mituuz/fuzzier/util/FuzzierUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ class FuzzierUtil {
return "${baseDimensionKey}_${screenBounds.width}_${screenBounds.height}_${screenBounds.x}_${screenBounds.y}"
}

fun fileIndexToIterationFile(iterationFiles: ConcurrentHashMap.KeySetView<IterationFile, Boolean>,
fileIndex: FileIndex, moduleName: String, task: Future<*>?,
isDir: Boolean = false) {
fun fileIndexToIterationFile(
iterationFiles: ConcurrentHashMap.KeySetView<IterationFile, Boolean>,
fileIndex: FileIndex, moduleName: String, task: Future<*>?,
isDir: Boolean = false
) {
fileIndex.iterateContent { file ->
if (task?.isCancelled == true) {
return@iterateContent false
Expand All @@ -67,6 +69,15 @@ class FuzzierUtil {
true
}
}

fun cleanSearchString(ss: String, ignoredChars: String): String {
var ret = ss.lowercase()
for (i in ignoredChars.toSet()) {
ret = ret.filterNot { it == i.lowercaseChar() }
}

return ret;
}
}

/**
Expand All @@ -81,14 +92,17 @@ class FuzzierUtil {
*
* @return a sorted and sized list model
*/
fun sortAndLimit(listModel: DefaultListModel<FuzzyMatchContainer>, isDirSort: Boolean = false): DefaultListModel<FuzzyMatchContainer> {
fun sortAndLimit(
listModel: DefaultListModel<FuzzyMatchContainer>,
isDirSort: Boolean = false
): DefaultListModel<FuzzyMatchContainer> {
val useShortDirPath = isDirSort && prioritizeShorterDirPaths
var comparator = getComparator(useShortDirPath, false)
val priorityQueue = PriorityQueue(listLimit + 1, comparator)

var minimumScore: Int? = null
listModel.elements().toList().forEach {
if (minimumScore == null || it.getScore() > minimumScore) {
if (minimumScore == null || it.getScore() > minimumScore!!) {
priorityQueue.add(it)
if (priorityQueue.size > listLimit) {
priorityQueue.remove()
Expand Down Expand Up @@ -154,7 +168,8 @@ class FuzzierUtil {
var prevModule: ModuleContainer? = null
for (currentModule in moduleList.sortedBy { it.basePath }) {
if (prevModule != null && (currentModule.basePath.startsWith(prevModule.basePath)
|| prevModule.basePath.startsWith(currentModule.basePath))) {
|| prevModule.basePath.startsWith(currentModule.basePath))
) {
if (currentModule.basePath.length > prevModule.basePath.length) {
currentModule.basePath = prevModule.basePath;
} else {
Expand Down Expand Up @@ -192,7 +207,7 @@ class FuzzierUtil {
return contentRoots.firstOrNull()?.path
}

data class ModuleContainer(val name:String, var basePath:String)
data class ModuleContainer(val name: String, var basePath: String)

private fun listToMap(modules: List<ModuleContainer>): Map<String, String> {
return modules.associateBy({ it.name }, { it.basePath })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ class FuzzierSettingsConfigurableTest {
assertTrue(settingsConfigurable.isModified())
}

@Test
fun excludedCharacters() {
pre()
state.ignoredCharacters = "abc"
assertTrue(settingsConfigurable.isModified())
}

@Test
fun newTab() {
pre()
Expand Down
14 changes: 14 additions & 0 deletions src/test/kotlin/com/mituuz/fuzzier/util/FuzzierUtilTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,20 @@ class FuzzierUtilTest {
assertEquals("file3", result[3].filename)
}

@Test
fun `Test ignored characters`() {
val searchString = "HELLO/THERE/GENERAL/KENOBI"
val ignoredChars = "H/"
assertEquals("elloteregeneralkenobi", FuzzierUtil.cleanSearchString(searchString, ignoredChars))
}

@Test
fun `No ignored characters`() {
val searchString = "!#¤%(&`Soqwe'"
val ignoredChars = ""
assertEquals(searchString.lowercase(), FuzzierUtil.cleanSearchString(searchString, ignoredChars))
}

private fun addElement(score: Int, fileName: String) {
val fuzzyScore = FuzzyScore()
fuzzyScore.streakScore = score
Expand Down
Loading