mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-07-29 16:59:01 +02:00
Add linewise motion type
This commit is contained in:
parent
ab8de509d9
commit
24e7f655fc
src/com/maddyhome/idea/vim
action
change
motion
mark
object
screen
updown
MotionArrowDownAction.ktMotionArrowUpAction.ktMotionDownActions.ktMotionDownFirstNonSpaceAction.ktMotionDownLess1FirstNonSpaceAction.ktMotionGotoLineFirstAction.ktMotionGotoLineLastAction.ktMotionGotoLineLastEndAction.ktMotionPercentOrMatchAction.ktMotionUpActions.ktMotionUpFirstNonSpaceAction.kt
visual
command
extension/textobjentire
group
@ -51,7 +51,7 @@ class OperatorAction : VimActionHandler.SingleExecution() {
|
||||
.getMotionRange(editor, editor.caretModel.primaryCaret, context, cmd.count, cmd.rawCount, argument)
|
||||
if (range != null) {
|
||||
VimPlugin.getMark().setChangeMarks(editor, range)
|
||||
val selectionType = SelectionType.fromCommandFlags(motion.flags)
|
||||
val selectionType = if (motion.isLinewiseMotion()) SelectionType.LINE_WISE else SelectionType.CHARACTER_WISE
|
||||
KeyHandler.getInstance().reset(editor)
|
||||
val result = operatorFunction.apply(editor, context, selectionType)
|
||||
VimRepeater.repeatHandler = saveRepeatHandler
|
||||
|
@ -29,11 +29,11 @@ import com.maddyhome.idea.vim.handler.MotionActionHandler
|
||||
import java.util.*
|
||||
|
||||
class MotionGotoFileMarkLineAction : MotionActionHandler.ForEachCaret() {
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override val argumentType: Argument.Type = Argument.Type.CHARACTER
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = EnumSet.of(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_SAVE_JUMP)
|
||||
override val flags: EnumSet<CommandFlags> = EnumSet.of(CommandFlags.FLAG_SAVE_JUMP)
|
||||
|
||||
override fun getOffset(editor: Editor,
|
||||
caret: Caret,
|
||||
@ -49,12 +49,10 @@ class MotionGotoFileMarkLineAction : MotionActionHandler.ForEachCaret() {
|
||||
}
|
||||
|
||||
class MotionGotoFileMarkLineNoSaveJumpAction : MotionActionHandler.ForEachCaret() {
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override val argumentType: Argument.Type = Argument.Type.CHARACTER
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = EnumSet.of(CommandFlags.FLAG_MOT_LINEWISE)
|
||||
|
||||
override fun getOffset(editor: Editor,
|
||||
caret: Caret,
|
||||
context: DataContext,
|
||||
|
@ -29,11 +29,11 @@ import com.maddyhome.idea.vim.handler.MotionActionHandler
|
||||
import java.util.*
|
||||
|
||||
class MotionGotoMarkLineAction : MotionActionHandler.ForEachCaret() {
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override val argumentType: Argument.Type = Argument.Type.CHARACTER
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = EnumSet.of(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_SAVE_JUMP)
|
||||
override val flags: EnumSet<CommandFlags> = EnumSet.of(CommandFlags.FLAG_SAVE_JUMP)
|
||||
|
||||
override fun getOffset(editor: Editor,
|
||||
caret: Caret,
|
||||
@ -49,12 +49,10 @@ class MotionGotoMarkLineAction : MotionActionHandler.ForEachCaret() {
|
||||
}
|
||||
|
||||
class MotionGotoMarkLineNoSaveJumpAction : MotionActionHandler.ForEachCaret() {
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override val argumentType: Argument.Type = Argument.Type.CHARACTER
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = EnumSet.of(CommandFlags.FLAG_MOT_LINEWISE)
|
||||
|
||||
override fun getOffset(editor: Editor,
|
||||
caret: Caret,
|
||||
context: DataContext,
|
||||
|
@ -33,7 +33,7 @@ import java.util.*
|
||||
|
||||
class MotionInnerParagraphAction : TextObjectActionHandler() {
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_TEXT_BLOCK)
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_TEXT_BLOCK)
|
||||
|
||||
override val visualType: TextObjectVisualType = TextObjectVisualType.LINE_WISE
|
||||
|
||||
|
@ -33,7 +33,7 @@ import java.util.*
|
||||
|
||||
class MotionOuterParagraphAction : TextObjectActionHandler() {
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_TEXT_BLOCK)
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_TEXT_BLOCK)
|
||||
|
||||
override val visualType: TextObjectVisualType = TextObjectVisualType.LINE_WISE
|
||||
|
||||
|
@ -29,7 +29,9 @@ import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.util.*
|
||||
|
||||
class MotionFirstScreenLineAction : MotionActionHandler.ForEachCaret() {
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_SAVE_JUMP)
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_SAVE_JUMP)
|
||||
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override fun getOffset(editor: Editor,
|
||||
caret: Caret,
|
||||
@ -39,6 +41,4 @@ class MotionFirstScreenLineAction : MotionActionHandler.ForEachCaret() {
|
||||
argument: Argument?): Int {
|
||||
return VimPlugin.getMotion().moveCaretToFirstScreenLine(editor, count)
|
||||
}
|
||||
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
}
|
||||
|
@ -29,7 +29,9 @@ import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.util.*
|
||||
|
||||
class MotionLastScreenLineAction : MotionActionHandler.ForEachCaret() {
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_SAVE_JUMP)
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_SAVE_JUMP)
|
||||
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override fun getOffset(editor: Editor,
|
||||
caret: Caret,
|
||||
@ -39,6 +41,4 @@ class MotionLastScreenLineAction : MotionActionHandler.ForEachCaret() {
|
||||
argument: Argument?): Int {
|
||||
return VimPlugin.getMotion().moveCaretToLastScreenLine(editor, count)
|
||||
}
|
||||
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
}
|
||||
|
@ -29,7 +29,9 @@ import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.util.*
|
||||
|
||||
class MotionMiddleScreenLineAction : MotionActionHandler.ForEachCaret() {
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_SAVE_JUMP)
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_SAVE_JUMP)
|
||||
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override fun getOffset(editor: Editor,
|
||||
caret: Caret,
|
||||
@ -39,6 +41,4 @@ class MotionMiddleScreenLineAction : MotionActionHandler.ForEachCaret() {
|
||||
argument: Argument?): Int {
|
||||
return VimPlugin.getMotion().moveCaretToMiddleScreenLine(editor)
|
||||
}
|
||||
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
}
|
||||
|
@ -25,22 +25,18 @@ import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.action.ComplicatedKeysAction
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.MotionType
|
||||
import com.maddyhome.idea.vim.handler.NonShiftedSpecialKeyHandler
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.awt.event.KeyEvent
|
||||
import java.util.*
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
class MotionArrowDownAction : NonShiftedSpecialKeyHandler(), ComplicatedKeysAction {
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override val keyStrokesSet: Set<MutableList<KeyStroke>> = setOf(parseKeys("<Down>"), mutableListOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_DOWN, 0)))
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE)
|
||||
private var col: Int = 0
|
||||
|
||||
override fun offset(editor: Editor, caret: Caret, context: DataContext, count: Int, rawCount: Int, argument: Argument?): Int {
|
||||
|
@ -25,22 +25,18 @@ import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.action.ComplicatedKeysAction
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.MotionType
|
||||
import com.maddyhome.idea.vim.handler.NonShiftedSpecialKeyHandler
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.awt.event.KeyEvent
|
||||
import java.util.*
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
class MotionArrowUpAction : NonShiftedSpecialKeyHandler(), ComplicatedKeysAction {
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(parseKeys("<Up>"), listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_UP, 0)))
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE)
|
||||
private var col: Int = 0
|
||||
|
||||
override fun offset(editor: Editor, caret: Caret, context: DataContext, count: Int, rawCount: Int, argument: Argument?): Int {
|
||||
|
@ -28,12 +28,9 @@ import com.intellij.openapi.editor.actionSystem.EditorActionManager
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.MotionType
|
||||
import com.maddyhome.idea.vim.handler.MotionActionHandler
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.util.*
|
||||
|
||||
sealed class MotionDownBase : MotionActionHandler.ForEachCaret() {
|
||||
private var col: Int = 0
|
||||
@ -50,9 +47,7 @@ sealed class MotionDownBase : MotionActionHandler.ForEachCaret() {
|
||||
|
||||
open class MotionDownAction : MotionDownBase() {
|
||||
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE)
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override fun getOffset(editor: Editor, caret: Caret, context: DataContext, count: Int, rawCount: Int, argument: Argument?): Int {
|
||||
return VimPlugin.getMotion().moveCaretVertical(editor, caret, count)
|
||||
|
@ -26,16 +26,11 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.MotionType
|
||||
import com.maddyhome.idea.vim.handler.MotionActionHandler
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.util.*
|
||||
|
||||
class MotionDownFirstNonSpaceAction : MotionActionHandler.ForEachCaret() {
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE)
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override fun getOffset(editor: Editor,
|
||||
caret: Caret,
|
||||
@ -48,9 +43,7 @@ class MotionDownFirstNonSpaceAction : MotionActionHandler.ForEachCaret() {
|
||||
}
|
||||
|
||||
class EnterNormalAction : MotionActionHandler.ForEachCaret() {
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE)
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override fun getOffset(editor: Editor,
|
||||
caret: Caret,
|
||||
|
@ -22,14 +22,11 @@ import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.MotionType
|
||||
import com.maddyhome.idea.vim.handler.MotionActionHandler
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.util.*
|
||||
|
||||
class MotionDownLess1FirstNonSpaceAction : MotionActionHandler.ForEachCaret() {
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE)
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override fun getOffset(editor: Editor,
|
||||
caret: Caret,
|
||||
@ -39,6 +36,4 @@ class MotionDownLess1FirstNonSpaceAction : MotionActionHandler.ForEachCaret() {
|
||||
argument: Argument?): Int {
|
||||
return VimPlugin.getMotion().moveCaretToLineStartSkipLeadingOffset(editor, caret, count - 1)
|
||||
}
|
||||
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
}
|
||||
|
@ -30,9 +30,9 @@ import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.util.*
|
||||
|
||||
class MotionGotoLineFirstAction : MotionActionHandler.ForEachCaret() {
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_SAVE_JUMP)
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_SAVE_JUMP)
|
||||
|
||||
override fun getOffset(editor: Editor,
|
||||
caret: Caret,
|
||||
|
@ -29,7 +29,9 @@ import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.util.*
|
||||
|
||||
class MotionGotoLineLastAction : MotionActionHandler.ForEachCaret() {
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_SAVE_JUMP)
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_SAVE_JUMP)
|
||||
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override fun getOffset(editor: Editor,
|
||||
caret: Caret,
|
||||
@ -39,6 +41,4 @@ class MotionGotoLineLastAction : MotionActionHandler.ForEachCaret() {
|
||||
argument: Argument?): Int {
|
||||
return VimPlugin.getMotion().moveCaretGotoLineLast(editor, rawCount)
|
||||
}
|
||||
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ import com.maddyhome.idea.vim.option.OptionsManager
|
||||
import java.util.*
|
||||
|
||||
class MotionGotoLineLastEndAction : MotionActionHandler.ForEachCaret() {
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_SAVE_JUMP)
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_SAVE_JUMP)
|
||||
|
||||
override fun getOffset(editor: Editor,
|
||||
caret: Caret,
|
||||
|
@ -46,10 +46,8 @@ class MotionPercentOrMatchAction : MotionActionHandler.ForEachCaret() {
|
||||
}
|
||||
|
||||
override fun process(cmd: Command) {
|
||||
if (cmd.rawCount != 0) {
|
||||
cmd.flags = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE)
|
||||
}
|
||||
motionType = if (cmd.rawCount != 0) MotionType.LINE_WISE else MotionType.INCLUSIVE
|
||||
}
|
||||
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
override var motionType: MotionType = MotionType.INCLUSIVE
|
||||
}
|
||||
|
@ -28,12 +28,9 @@ import com.intellij.openapi.editor.actionSystem.EditorActionManager
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.MotionType
|
||||
import com.maddyhome.idea.vim.handler.MotionActionHandler
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.util.*
|
||||
|
||||
sealed class MotionUpBase : MotionActionHandler.ForEachCaret() {
|
||||
private var col: Int = 0
|
||||
@ -49,9 +46,7 @@ sealed class MotionUpBase : MotionActionHandler.ForEachCaret() {
|
||||
}
|
||||
|
||||
open class MotionUpAction : MotionUpBase() {
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE)
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override fun getOffset(editor: Editor, caret: Caret, context: DataContext, count: Int, rawCount: Int, argument: Argument?): Int {
|
||||
return VimPlugin.getMotion().moveCaretVertical(editor, caret, -count)
|
||||
|
@ -22,14 +22,11 @@ import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.MotionType
|
||||
import com.maddyhome.idea.vim.handler.MotionActionHandler
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.util.*
|
||||
|
||||
class MotionUpFirstNonSpaceAction : MotionActionHandler.ForEachCaret() {
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE)
|
||||
override val motionType: MotionType = MotionType.LINE_WISE
|
||||
|
||||
override fun getOffset(editor: Editor,
|
||||
caret: Caret,
|
||||
@ -39,6 +36,4 @@ class MotionUpFirstNonSpaceAction : MotionActionHandler.ForEachCaret() {
|
||||
argument: Argument?): Int {
|
||||
return VimPlugin.getMotion().moveCaretToLineStartSkipLeadingOffset(editor, caret, -count)
|
||||
}
|
||||
|
||||
override val motionType: MotionType = MotionType.INCLUSIVE
|
||||
}
|
||||
|
@ -22,22 +22,17 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.group.visual.vimSetSelection
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import com.maddyhome.idea.vim.helper.vimForEachCaret
|
||||
import com.maddyhome.idea.vim.option.OptionsManager
|
||||
import java.util.*
|
||||
|
||||
|
||||
class VisualToggleLineModeAction : VimActionHandler.SingleExecution() {
|
||||
|
||||
override val type: Command.Type = Command.Type.OTHER_READONLY
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
|
||||
val listOption = OptionsManager.selectmode
|
||||
return if ("cmd" in listOption) {
|
||||
|
@ -22,7 +22,7 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.group.visual.VimSelection
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
import com.maddyhome.idea.vim.handler.MotionActionHandler
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@ -46,10 +46,10 @@ class Argument private constructor(
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val EMPTY_COMMAND = Command(0, object : VimActionHandler.SingleExecution() {
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean = true
|
||||
val EMPTY_COMMAND = Command(0, object : MotionActionHandler.SingleExecution() {
|
||||
override fun getOffset(editor: Editor, context: DataContext, count: Int, rawCount: Int, argument: Argument?) = 0
|
||||
|
||||
override val type: Command.Type = Command.Type.MOTION
|
||||
override val motionType: MotionType = MotionType.EXCLUSIVE
|
||||
}, Command.Type.MOTION, EnumSet.noneOf(CommandFlags::class.java))
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase
|
||||
import com.maddyhome.idea.vim.handler.MotionActionHandler
|
||||
import com.maddyhome.idea.vim.handler.TextObjectActionHandler
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@ -52,6 +54,14 @@ data class Command(
|
||||
var argument: Argument? = null
|
||||
var register: Char? = null
|
||||
|
||||
fun isLinewiseMotion(): Boolean {
|
||||
return when (action) {
|
||||
is TextObjectActionHandler -> (action as TextObjectActionHandler).visualType == TextObjectVisualType.LINE_WISE
|
||||
is MotionActionHandler -> (action as MotionActionHandler).motionType == MotionType.LINE_WISE
|
||||
else -> error("Command is not a motion: $action")
|
||||
}
|
||||
}
|
||||
|
||||
enum class Type {
|
||||
/**
|
||||
* Represents commands that actually move the cursor and can be arguments to operators.
|
||||
|
@ -20,7 +20,8 @@ package com.maddyhome.idea.vim.command
|
||||
|
||||
enum class MotionType {
|
||||
INCLUSIVE,
|
||||
EXCLUSIVE
|
||||
EXCLUSIVE,
|
||||
LINE_WISE
|
||||
}
|
||||
|
||||
enum class TextObjectVisualType {
|
||||
|
@ -18,7 +18,6 @@
|
||||
package com.maddyhome.idea.vim.command
|
||||
|
||||
import com.maddyhome.idea.vim.command.CommandState.SubMode
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
@ -52,12 +51,6 @@ enum class SelectionType(val value: Int) {
|
||||
SubMode.VISUAL_BLOCK -> BLOCK_WISE
|
||||
else -> CHARACTER_WISE
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun fromCommandFlags(flags: EnumSet<CommandFlags>) = when {
|
||||
CommandFlags.FLAG_MOT_LINEWISE in flags -> LINE_WISE
|
||||
else -> CHARACTER_WISE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ public class VimTextObjEntireExtension implements VimExtension {
|
||||
@NotNull
|
||||
@Override
|
||||
public TextObjectVisualType getVisualType() {
|
||||
return TextObjectVisualType.LINE_WISE;
|
||||
return TextObjectVisualType.CHARACTER_WISE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1074,9 +1074,14 @@ public class ChangeGroup {
|
||||
// 1) The range is across multiple lines
|
||||
// 2) There is only whitespace before the start of the range
|
||||
// 3) There is only whitespace after the end of the range
|
||||
SelectionType type = SelectionType.fromCommandFlags(argument.getMotion().getFlags());
|
||||
SelectionType type;
|
||||
if (argument.getMotion().isLinewiseMotion()) {
|
||||
type = SelectionType.LINE_WISE;
|
||||
} else {
|
||||
type = SelectionType.CHARACTER_WISE;
|
||||
}
|
||||
final Command motion = argument.getMotion();
|
||||
if (!isChange && !motion.getFlags().contains(CommandFlags.FLAG_MOT_LINEWISE)) {
|
||||
if (!isChange && !motion.isLinewiseMotion()) {
|
||||
LogicalPosition start = editor.offsetToLogicalPosition(range.getStartOffset());
|
||||
LogicalPosition end = editor.offsetToLogicalPosition(range.getEndOffset());
|
||||
if (start.line != end.line) {
|
||||
|
@ -111,9 +111,7 @@ public class MotionGroup {
|
||||
if (end == -1) return null;
|
||||
|
||||
// If inclusive, add the last character to the range
|
||||
if (action.getMotionType() == MotionType.INCLUSIVE &&
|
||||
!cmd.getFlags().contains(CommandFlags.FLAG_MOT_LINEWISE) &&
|
||||
end < EditorHelperRt.getFileSize(editor)) {
|
||||
if (action.getMotionType() == MotionType.INCLUSIVE && end < EditorHelperRt.getFileSize(editor)) {
|
||||
end++;
|
||||
}
|
||||
}
|
||||
@ -127,7 +125,7 @@ public class MotionGroup {
|
||||
start = range.getStartOffset();
|
||||
end = range.getEndOffset();
|
||||
|
||||
if (cmd.getFlags().contains(CommandFlags.FLAG_MOT_LINEWISE)) end--;
|
||||
if (cmd.isLinewiseMotion()) end--;
|
||||
} else {
|
||||
throw new RuntimeException("Commands doesn't take " + cmd.getAction().getClass().getSimpleName() + " as an operator");
|
||||
}
|
||||
@ -142,7 +140,7 @@ public class MotionGroup {
|
||||
// If we are a linewise motion we need to normalize the start and stop then move the start to the beginning
|
||||
// of the line and move the end to the end of the line.
|
||||
EnumSet<CommandFlags> flags = cmd.getFlags();
|
||||
if (flags.contains(CommandFlags.FLAG_MOT_LINEWISE)) {
|
||||
if (cmd.isLinewiseMotion()) {
|
||||
if (caret.getLogicalPosition().line != EditorHelper.getLineCount(editor) - 1) {
|
||||
start = EditorHelper.getLineStartForOffset(editor, start);
|
||||
end = Math.min(EditorHelper.getLineEndForOffset(editor, end) + 1, EditorHelperRt.getFileSize(editor));
|
||||
|
@ -64,7 +64,7 @@ class YankGroup {
|
||||
startOffsets?.put(caret, motionRange.normalize().startOffset)
|
||||
}
|
||||
|
||||
val type = SelectionType.fromCommandFlags(motion.flags)
|
||||
val type = if (motion.isLinewiseMotion()) SelectionType.LINE_WISE else SelectionType.CHARACTER_WISE
|
||||
val range = getTextRange(ranges, type) ?: return false
|
||||
|
||||
if (range.size() == 0) return false
|
||||
|
Loading…
Reference in New Issue
Block a user