diff --git a/build.gradle.kts b/build.gradle.kts
index d4943384..6403475e 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
// Use the same version and group for the jar and the plugin
-val currentVersion = "2.4.0"
+val currentVersion = "2.4.1"
val myGroup = "com.mituuz"
version = currentVersion
group = myGroup
@@ -39,6 +39,12 @@ intellijPlatform {
changeNotes = """
Version $currentVersion
+
+ -
+ Add list rollover support
+
+
+ Version 2.4.0
-
Add file recency scoring
diff --git a/changelog.md b/changelog.md
index 8f4472f7..981b9373 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,9 @@
# Changelog
+## Version 2.4.1
+
+- Add list rollover support
+
## Version 2.4.0
- Add file recency scoring
diff --git a/readme.md b/readme.md
index 22576af9..71579c6f 100644
--- a/readme.md
+++ b/readme.md
@@ -45,7 +45,8 @@ List movement can be remapped from settings -> keymaps, but do not support chord
- Fuzzy file search
- Search all except excluded files
- Search only from VCS-tracked files
-- Text search leveraging [ripgrep](https://github.com/BurntSushi/ripgrep "Link to GitHub - ripgrep"), grep or findstr
+- Text search leveraging [ripgrep](https://github.com/BurntSushi/ripgrep "Link to GitHub - ripgrep") or a native
+ implementation
- Support for searching from the whole project, within open tabs or the current buffer
- With file extension support for ripgrep in the secondary search field
- File mover
diff --git a/src/main/kotlin/com/mituuz/fuzzier/actions/FuzzyAction.kt b/src/main/kotlin/com/mituuz/fuzzier/actions/FuzzyAction.kt
index 799d953c..a4ae220b 100644
--- a/src/main/kotlin/com/mituuz/fuzzier/actions/FuzzyAction.kt
+++ b/src/main/kotlin/com/mituuz/fuzzier/actions/FuzzyAction.kt
@@ -59,6 +59,7 @@ import java.awt.Font
import java.awt.event.ActionEvent
import java.util.concurrent.ConcurrentHashMap
import javax.swing.*
+import kotlin.time.Duration.Companion.milliseconds
abstract class FuzzyAction : AnAction() {
companion object {
@@ -160,7 +161,7 @@ abstract class FuzzyAction : AnAction() {
debounceJob?.cancel()
val debouncePeriod = globalState.debouncePeriod
debounceJob = actionScope?.launch {
- delay(debouncePeriod.toLong())
+ delay(debouncePeriod.toLong().milliseconds)
updateListContents(project, component.searchField.text)
}
}
@@ -225,20 +226,37 @@ abstract class FuzzyAction : AnAction() {
}
fun moveListUp() {
- val selectedIndex = component.fileList.selectedIndex
- if (selectedIndex > 0) {
- component.fileList.selectedIndex = selectedIndex - 1
- component.fileList.ensureIndexIsVisible(selectedIndex - 1)
+ val fileList = component.fileList
+ val listSize = fileList.model.size
+
+ if (listSize == 0) return
+
+ val currentIndex = fileList.selectedIndex
+ val newIndex = if (currentIndex in 1 until listSize) {
+ currentIndex - 1
+ } else {
+ listSize - 1
}
+
+ fileList.selectedIndex = newIndex
+ fileList.ensureIndexIsVisible(newIndex)
}
fun moveListDown() {
- val selectedIndex = component.fileList.selectedIndex
- val length = component.fileList.model.size
- if (selectedIndex < length - 1) {
- component.fileList.selectedIndex = selectedIndex + 1
- component.fileList.ensureIndexIsVisible(selectedIndex + 1)
+ val fileList = component.fileList
+ val listSize = fileList.model.size
+
+ if (listSize == 0) return
+
+ val currentIndex = fileList.selectedIndex
+ val newIndex = if (currentIndex < listSize - 1) {
+ currentIndex + 1
+ } else {
+ 0
}
+
+ fileList.selectedIndex = newIndex
+ fileList.ensureIndexIsVisible(newIndex)
}
fun getCellRenderer(): ListCellRenderer {
diff --git a/src/test/kotlin/com/mituuz/fuzzier/FuzzyActionTest.kt b/src/test/kotlin/com/mituuz/fuzzier/FuzzyActionTest.kt
index 20b6f242..8bbccfc9 100644
--- a/src/test/kotlin/com/mituuz/fuzzier/FuzzyActionTest.kt
+++ b/src/test/kotlin/com/mituuz/fuzzier/FuzzyActionTest.kt
@@ -33,6 +33,7 @@ import com.intellij.testFramework.TestApplicationManager
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.mituuz.fuzzier.actions.FuzzyAction
import com.mituuz.fuzzier.components.SimpleFinderComponent
+import com.mituuz.fuzzier.entities.FuzzyContainer
import com.mituuz.fuzzier.entities.FuzzyContainer.FilenameType.*
import com.mituuz.fuzzier.entities.FuzzyMatchContainer
import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FileType.FILE
@@ -41,10 +42,7 @@ import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import java.awt.event.InputEvent
import java.awt.event.KeyEvent
-import javax.swing.JComponent
-import javax.swing.JLabel
-import javax.swing.JList
-import javax.swing.KeyStroke
+import javax.swing.*
class FuzzyActionTest {
@Suppress("unused")
@@ -185,6 +183,48 @@ class FuzzyActionTest {
assertEquals(expectedIcon, component.icon)
}
+ @Test
+ fun `Test moveListUp rollover`() {
+ val action = getAction()
+ action.component = SimpleFinderComponent()
+ val model = DefaultListModel()
+ model.addElement(FuzzyMatchContainer(FuzzyScore(), "/src/asd1", "asd1", "", FILE))
+ model.addElement(FuzzyMatchContainer(FuzzyScore(), "/src/asd2", "asd2", "", FILE))
+ model.addElement(FuzzyMatchContainer(FuzzyScore(), "/src/asd3", "asd3", "", FILE))
+ action.component.fileList.model = model
+ action.component.fileList.selectedIndex = 0
+
+ action.moveListUp()
+ assertEquals(2, action.component.fileList.selectedIndex)
+
+ action.moveListUp()
+ assertEquals(1, action.component.fileList.selectedIndex)
+
+ action.moveListUp()
+ assertEquals(0, action.component.fileList.selectedIndex)
+ }
+
+ @Test
+ fun `Test moveListDown rollover`() {
+ val action = getAction()
+ action.component = SimpleFinderComponent()
+ val model = DefaultListModel()
+ model.addElement(FuzzyMatchContainer(FuzzyScore(), "/src/asd1", "asd1", "", FILE))
+ model.addElement(FuzzyMatchContainer(FuzzyScore(), "/src/asd2", "asd2", "", FILE))
+ model.addElement(FuzzyMatchContainer(FuzzyScore(), "/src/asd3", "asd3", "", FILE))
+ action.component.fileList.model = model
+ action.component.fileList.selectedIndex = 2
+
+ action.moveListDown()
+ assertEquals(0, action.component.fileList.selectedIndex)
+
+ action.moveListDown()
+ assertEquals(1, action.component.fileList.selectedIndex)
+
+ action.moveListDown()
+ assertEquals(2, action.component.fileList.selectedIndex)
+ }
+
private fun getAction(): FuzzyAction {
return object : FuzzyAction() {
override fun actionPerformed(actionEvent: AnActionEvent) {