1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-08-10 15:40:37 +02:00

Create noneOfEnum helper function

This commit is contained in:
Alex Plate 2019-06-11 13:15:52 +03:00
parent 778ddb0e75
commit a1adb1eb43
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
4 changed files with 8 additions and 7 deletions
src/com/maddyhome/idea/vim
test/org/jetbrains/plugins/ideavim/action/motion/gn

View File

@ -30,6 +30,7 @@ import com.maddyhome.idea.vim.handler.ExecuteMethodNotOverriddenException
import com.maddyhome.idea.vim.helper.MessageHelper
import com.maddyhome.idea.vim.helper.Msg
import com.maddyhome.idea.vim.helper.inVisualMode
import com.maddyhome.idea.vim.helper.noneOfEnum
import java.util.*
/**
@ -114,7 +115,7 @@ abstract class CommandHandler {
argFlags: CommandHandlerFlags,
runForEachCaret: Boolean = false,
caretOrder: CaretOrder = CaretOrder.DECREASING_OFFSET,
optFlags: EnumSet<CommandFlags> = EnumSet.noneOf<CommandFlags>(CommandFlags::class.java)
optFlags: EnumSet<CommandFlags> = noneOfEnum()
) {
this.names = names
this.argFlags = argFlags

View File

@ -22,6 +22,7 @@ import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.UserDataHolder
import java.util.*
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
@ -106,6 +107,7 @@ fun <T> userDataOr(default: UserDataHolder.() -> T): ReadWriteProperty<UserDataH
}
fun <T : Comparable<T>> sort(a: T, b: T) = if (a > b) b to a else a to b
inline fun <reified T : Enum<T>> noneOfEnum(): EnumSet<T> = EnumSet.noneOf(T::class.java)
inline fun Editor.vimForEachCaret(action: (caret: Caret) -> Unit) {
if (this.inBlockSubMode) {

View File

@ -21,11 +21,10 @@
package org.jetbrains.plugins.ideavim.action.motion.gn
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
import com.maddyhome.idea.vim.helper.noneOfEnum
import org.jetbrains.plugins.ideavim.VimTestCase
import java.util.*
import javax.swing.KeyStroke
class GnNextTextObjectTest : VimTestCase() {
@ -69,7 +68,7 @@ class GnNextTextObjectTest : VimTestCase() {
private fun doTestWithSearch(keys: List<KeyStroke>, before: String,
after: String) {
configureByText(before)
VimPlugin.getSearch().search(myFixture.editor, "test", 1, EnumSet.noneOf(CommandFlags::class.java), false)
VimPlugin.getSearch().search(myFixture.editor, "test", 1, noneOfEnum(), false)
typeText(keys)
myFixture.checkResult(after)
assertState(CommandState.Mode.COMMAND, CommandState.SubMode.NONE)

View File

@ -21,11 +21,10 @@
package org.jetbrains.plugins.ideavim.action.motion.gn
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
import com.maddyhome.idea.vim.helper.noneOfEnum
import org.jetbrains.plugins.ideavim.VimTestCase
import java.util.*
import javax.swing.KeyStroke
class GnPreviousTextObjectTest : VimTestCase() {
@ -52,7 +51,7 @@ class GnPreviousTextObjectTest : VimTestCase() {
private fun doTestWithSearch(keys: List<KeyStroke>, before: String,
after: String) {
configureByText(before)
VimPlugin.getSearch().search(myFixture.editor, "test", 1, EnumSet.noneOf(CommandFlags::class.java), false)
VimPlugin.getSearch().search(myFixture.editor, "test", 1, noneOfEnum(), false)
typeText(keys)
myFixture.checkResult(after)
assertState(CommandState.Mode.COMMAND, CommandState.SubMode.NONE)