Skip to content

Commit

Permalink
VIM-566: Add za motion support for toggling folds
Browse files Browse the repository at this point in the history
  • Loading branch information
The1xDeveloper authored and AlexPl292 committed Aug 16, 2024
1 parent 2189b70 commit 3ba14d0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ internal class IjActionExecutor : VimActionExecutor {
get() = IdeActions.ACTION_EXPAND_REGION
override val ACTION_EXPAND_REGION_RECURSIVELY: String
get() = IdeActions.ACTION_EXPAND_REGION_RECURSIVELY
override val ACTION_EXPAND_COLLAPSE_TOGGLE: String
get() = "ExpandCollapseToggleAction"

/**
* Execute an action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimBehaviorDiffers
import org.jetbrains.plugins.ideavim.VimJavaTestCase
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

class ChangeActionJavaTest : VimJavaTestCase() {
// VIM-511 |.|
Expand Down Expand Up @@ -120,6 +121,28 @@ and some text after""",
)
}

// VIM-566
@TestWithoutNeovim(SkipNeovimReason.FOLDING)
@Test
fun testInsertAfterToggleFold() {
configureByJavaText(
"""
$c/**
* I should be fold
* a little more text
* and final fold
*/
and some text after
""".trimIndent(),
)
CodeFoldingManager.getInstance(fixture.project).updateFoldRegions(fixture.editor)
assertEquals(FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded, true)
typeText(injector.parser.parseKeys("za"))
assertEquals(FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded, false)
typeText(injector.parser.parseKeys("za"))
assertEquals(FoldingUtil.findFoldRegionStartingAtLine(fixture.editor, 0)!!.isExpanded, true)
}

// VIM-287 |zc| |o|
@TestWithoutNeovim(SkipNeovimReason.FOLDING)
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ class VimCollapseAllRegions : VimActionHandler.SingleExecution() {
}
}

@CommandOrMotion(keys = ["za"], modes = [Mode.NORMAL, Mode.VISUAL])
class VimExpandCollapseToggleRegion : VimActionHandler.SingleExecution() {

override val type: Command.Type = Command.Type.OTHER_READONLY

override fun execute(
editor: VimEditor,
context: ExecutionContext,
cmd: Command,
operatorArguments: OperatorArguments,
): Boolean {
injector.actionExecutor.executeAction(editor, name = injector.actionExecutor.ACTION_EXPAND_COLLAPSE_TOGGLE, context = context)
return true
}
}

@CommandOrMotion(keys = ["zc"], modes = [Mode.NORMAL, Mode.VISUAL])
class VimCollapseRegion : VimActionHandler.SingleExecution() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface VimActionExecutor {
val ACTION_EXPAND_ALL_REGIONS: String
val ACTION_EXPAND_REGION: String
val ACTION_EXPAND_REGION_RECURSIVELY: String
val ACTION_EXPAND_COLLAPSE_TOGGLE: String

/**
* Execute an action
Expand Down

0 comments on commit 3ba14d0

Please sign in to comment.