diff --git a/build.gradle.kts b/build.gradle.kts index aa7fea05..77f68a8b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "com.mituuz" -version = "0.25.0" +version = "0.25.1" repositories { mavenCentral() diff --git a/changelog.md b/changelog.md index bc28b130..3d3085df 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,8 @@ # Changelog +## Version 0.25.1 +- Fix task cancellation, making lower debounce time feel much better +- Lower default debounce time + ## Version 0.25.0 - Clear up settings grouping - Add option to highlight filename matches in the file list diff --git a/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt b/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt index 8564862b..d395f38c 100644 --- a/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt +++ b/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt @@ -46,11 +46,11 @@ import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.openapi.wm.WindowManager import com.mituuz.fuzzier.components.FuzzyFinderComponent import com.mituuz.fuzzier.entities.FuzzyMatchContainer -import com.mituuz.fuzzier.settings.FuzzierSettingsService import com.mituuz.fuzzier.settings.FuzzierSettingsService.RecentFilesMode.NONE import org.apache.commons.lang3.StringUtils import java.awt.event.* import javax.swing.* +import kotlin.coroutines.cancellation.CancellationException open class Fuzzier : FuzzyAction() { private var defaultDoc: Document? = null @@ -159,27 +159,39 @@ open class Fuzzier : FuzzyAction() { currentTask?.takeIf { !it.isDone }?.cancel(true) currentTask = ApplicationManager.getApplication().executeOnPooledThread { - component.fileList.setPaintBusy(true) - var listModel = DefaultListModel() + try { + // Create a reference to the current task to check if it has been cancelled + val task = currentTask + component.fileList.setPaintBusy(true) + var listModel = DefaultListModel() - val stringEvaluator = StringEvaluator( - fuzzierSettingsService.state.exclusionSet, - fuzzierSettingsService.state.modules, - changeListManager - ) + val stringEvaluator = StringEvaluator( + fuzzierSettingsService.state.exclusionSet, + fuzzierSettingsService.state.modules, + changeListManager + ) - val moduleManager = ModuleManager.getInstance(project) - processModules(moduleManager, stringEvaluator, searchString, listModel) + if (task?.isCancelled == true) throw CancellationException() - listModel = fuzzierUtil.sortAndLimit(listModel) + val moduleManager = ModuleManager.getInstance(project) + processModules(moduleManager, stringEvaluator, searchString, listModel) - ApplicationManager.getApplication().invokeLater { - component.fileList.model = listModel - component.fileList.cellRenderer = getCellRenderer() - component.fileList.setPaintBusy(false) - if (!component.fileList.isEmpty) { - component.fileList.setSelectedValue(listModel[0], true) + if (task?.isCancelled == true) throw CancellationException() + + listModel = fuzzierUtil.sortAndLimit(listModel) + + if (task?.isCancelled == true) throw CancellationException() + + ApplicationManager.getApplication().invokeLater { + component.fileList.model = listModel + component.fileList.cellRenderer = getCellRenderer() + component.fileList.setPaintBusy(false) + if (!component.fileList.isEmpty) { + component.fileList.setSelectedValue(listModel[0], true) + } } + } catch (e: CancellationException) { + // Do nothing } } } diff --git a/src/main/kotlin/com/mituuz/fuzzier/FuzzyMover.kt b/src/main/kotlin/com/mituuz/fuzzier/FuzzyMover.kt index a9573d82..af72029b 100644 --- a/src/main/kotlin/com/mituuz/fuzzier/FuzzyMover.kt +++ b/src/main/kotlin/com/mituuz/fuzzier/FuzzyMover.kt @@ -51,6 +51,7 @@ import org.apache.commons.lang3.StringUtils import java.awt.event.* import java.util.concurrent.CompletableFuture import javax.swing.* +import kotlin.coroutines.cancellation.CancellationException class FuzzyMover : FuzzyAction() { private val dimensionKey: String = "FuzzyMoverPopup" @@ -194,28 +195,39 @@ class FuzzyMover : FuzzyAction() { } currentTask?.takeIf { !it.isDone }?.cancel(true) - currentTask = ApplicationManager.getApplication().executeOnPooledThread { - component.fileList.setPaintBusy(true) - var listModel = DefaultListModel() + try { + // Create a reference to the current task to check if it has been cancelled + val task = currentTask + component.fileList.setPaintBusy(true) + var listModel = DefaultListModel() - val stringEvaluator = StringEvaluator( - fuzzierSettingsService.state.exclusionSet, - fuzzierSettingsService.state.modules - ) + val stringEvaluator = StringEvaluator( + fuzzierSettingsService.state.exclusionSet, + fuzzierSettingsService.state.modules + ) - val moduleManager = ModuleManager.getInstance(project) - processModules(moduleManager, stringEvaluator, searchString, listModel) + if (task?.isCancelled == true) throw CancellationException() - listModel = fuzzierUtil.sortAndLimit(listModel, true) + val moduleManager = ModuleManager.getInstance(project) + processModules(moduleManager, stringEvaluator, searchString, listModel) - ApplicationManager.getApplication().invokeLater { - component.fileList.model = listModel - component.fileList.cellRenderer = getCellRenderer() - component.fileList.setPaintBusy(false) - if (!component.fileList.isEmpty) { - component.fileList.setSelectedValue(listModel[0], true) + if (task?.isCancelled == true) throw CancellationException() + + listModel = fuzzierUtil.sortAndLimit(listModel, true) + + if (task?.isCancelled == true) throw CancellationException() + + ApplicationManager.getApplication().invokeLater { + component.fileList.model = listModel + component.fileList.cellRenderer = getCellRenderer() + component.fileList.setPaintBusy(false) + if (!component.fileList.isEmpty) { + component.fileList.setSelectedValue(listModel[0], true) + } } + } catch (e: CancellationException) { + // Do nothing } } } diff --git a/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt b/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt index 66a3264c..f08ab224 100644 --- a/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt +++ b/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt @@ -43,7 +43,7 @@ class FuzzierSettingsService : PersistentStateComponent = setOf("/.idea/*", "/.git/*", "/target/*", "/build/*", "/.gradle/*", "/.run/*") var newTab: Boolean = false var prioritizeShorterDirPaths = true - var debouncePeriod: Int = 150 + var debouncePeriod: Int = 80 var resetWindow = false var fileListLimit: Int = 50 diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index d27e0704..e9c1f422 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -29,6 +29,9 @@ Version 0.25.1 + - Fix task cancellation, making lower debounce time feel much better
+ - Lower default debounce time

Version 0.25.0

- Clear up settings grouping
- Add option to highlight filename matches in the file list