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
8 changes: 7 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,6 +39,12 @@ intellijPlatform {

changeNotes = """
<h2>Version $currentVersion</h2>
<ul>
<li>
Add list rollover support
</li>
</ul>
<h2>Version 2.4.0</h2>
<ul>
<li>
Add file recency scoring
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 2.4.1

- Add list rollover support

## Version 2.4.0

- Add file recency scoring
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 28 additions & 10 deletions src/main/kotlin/com/mituuz/fuzzier/actions/FuzzyAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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<Any?> {
Expand Down
48 changes: 44 additions & 4 deletions src/test/kotlin/com/mituuz/fuzzier/FuzzyActionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -185,6 +183,48 @@ class FuzzyActionTest {
assertEquals(expectedIcon, component.icon)
}

@Test
fun `Test moveListUp rollover`() {
val action = getAction()
action.component = SimpleFinderComponent()
val model = DefaultListModel<FuzzyContainer>()
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<FuzzyContainer>()
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) {
Expand Down
Loading