Skip to content

Commit

Permalink
Partial implementation of virtualedit config
Browse files Browse the repository at this point in the history
This does not support all config settings,
but does add the 'onemore' option.

This partly addresses https://youtrack.jetbrains.com/issue/VIM-844
  • Loading branch information
i-e-b committed Jun 26, 2020
1 parent 7008185 commit f7ff308
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.MotionType
import com.maddyhome.idea.vim.handler.NonShiftedSpecialKeyHandler
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
import com.maddyhome.idea.vim.helper.isEndAllowed
import com.maddyhome.idea.vim.helper.mode
import java.awt.event.KeyEvent
import javax.swing.KeyStroke

Expand All @@ -39,7 +41,8 @@ class MotionArrowRightAction : NonShiftedSpecialKeyHandler(), ComplicatedKeysAct
)

override fun offset(editor: Editor, caret: Caret, context: DataContext, count: Int, rawCount: Int, argument: Argument?): Int {
return VimPlugin.getMotion().moveCaretHorizontal(editor, caret, count, false)
val allowPastEnd = editor.mode.isEndAllowed
return VimPlugin.getMotion().moveCaretHorizontal(editor, caret, count, allowPastEnd)
}
}

3 changes: 2 additions & 1 deletion src/com/maddyhome/idea/vim/helper/CommandStateExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ package com.maddyhome.idea.vim.helper

import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.option.OptionsManager

val CommandState.Mode.isEndAllowed
get() = when (this) {
CommandState.Mode.INSERT, CommandState.Mode.VISUAL, CommandState.Mode.SELECT -> true
CommandState.Mode.COMMAND, CommandState.Mode.CMD_LINE, CommandState.Mode.REPLACE -> false
CommandState.Mode.COMMAND, CommandState.Mode.CMD_LINE, CommandState.Mode.REPLACE -> OptionsManager.virtualedit.value == "onemore"
}

val CommandState.Mode.isBlockCaret
Expand Down
1 change: 1 addition & 0 deletions src/com/maddyhome/idea/vim/option/OptionsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ object OptionsManager {
val idearefactormode = addOption(BoundStringOption(IdeaRefactorMode.name, IdeaRefactorMode.name, IdeaRefactorMode.select, IdeaRefactorMode.availableValues))
val ideastatusicon = addOption(BoundStringOption(IdeaStatusIcon.name, IdeaStatusIcon.name, IdeaStatusIcon.enabled, IdeaStatusIcon.allValues))
val ideastrictmode = addOption(ToggleOption("ideastrictmode", "ideastrictmode", false))
val virtualedit = addOption(BoundStringOption("virtualedit","ve","", arrayOf("block", "insert", "all", "onemore") ))

// Dev only experimental options
val dialogescape = addOption(BoundStringOption("dialogescape", "de", "legacy", arrayOf("legacy", "on", "off")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package org.jetbrains.plugins.ideavim.action.motion.leftright

import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
import com.maddyhome.idea.vim.option.OptionsManager
import org.jetbrains.plugins.ideavim.VimTestCase

class MotionRightActionTest : VimTestCase() {
Expand Down Expand Up @@ -79,6 +80,25 @@ class MotionRightActionTest : VimTestCase() {
""".trimIndent(), CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
}

fun `test virtual edit motion to the end`() {
OptionsManager.virtualedit.set("onemore")
doTest(parseKeys("3l"), """
A Discovery
I found it in a legendary lan${c}d
all rocks and lavender and tufted grass,
where it was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent(), """
A Discovery
I found it in a legendary land${c}
all rocks and lavender and tufted grass,
where it was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent(), CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
}

fun `test simple motion non-ascii`() {
doTest(parseKeys("l"), """
A Discovery
Expand Down

0 comments on commit f7ff308

Please sign in to comment.