mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-10 15:40:37 +02:00
Move some actions to vim-engine
This commit is contained in:
parent
6ddc40d080
commit
83da2d304e
src/main/java/com/maddyhome/idea/vim
action
group
helper
listener
newapi
vim-engine/src/main/kotlin/com/maddyhome/idea/vim
@ -26,6 +26,7 @@ import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import org.jetbrains.annotations.Contract
|
||||
import java.util.*
|
||||
|
||||
@ -41,7 +42,7 @@ class InsertBeforeCursorAction : ChangeEditorActionHandler.SingleExecution() {
|
||||
argument: Argument?,
|
||||
operatorArguments: OperatorArguments,
|
||||
): Boolean {
|
||||
VimPlugin.getChange().insertBeforeCursor(editor, context)
|
||||
VimPlugin.getChange().insertBeforeCursor(editor.vim, context.vim)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,12 @@ class SelectDeleteAction : VimActionHandler.SingleExecution() {
|
||||
|
||||
override val type: Command.Type = Command.Type.INSERT
|
||||
|
||||
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
||||
override fun execute(
|
||||
editor: VimEditor,
|
||||
context: ExecutionContext,
|
||||
cmd: Command,
|
||||
operatorArguments: OperatorArguments,
|
||||
): Boolean {
|
||||
val enterKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0)
|
||||
val actions = VimPlugin.getKey().getActions(editor.ij.component, enterKeyStroke)
|
||||
for (action in actions) {
|
||||
@ -48,7 +53,7 @@ class SelectDeleteAction : VimActionHandler.SingleExecution() {
|
||||
}
|
||||
}
|
||||
editor.exitSelectMode(true)
|
||||
VimPlugin.getChange().insertBeforeCursor(editor.ij, context.ij)
|
||||
VimPlugin.getChange().insertBeforeCursor(editor, context)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -115,8 +115,9 @@ public class ChangeGroup implements VimChangeGroup {
|
||||
* @param editor The editor to insert into
|
||||
* @param context The data context
|
||||
*/
|
||||
public void insertBeforeCursor(@NotNull Editor editor, @NotNull DataContext context) {
|
||||
initInsert(editor, context, CommandState.Mode.INSERT);
|
||||
@Override
|
||||
public void insertBeforeCursor(@NotNull VimEditor editor, @NotNull ExecutionContext context) {
|
||||
initInsert(((IjVimEditor)editor).getEditor(), ((IjExecutionContext)context).getContext(), CommandState.Mode.INSERT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -320,7 +321,7 @@ public class ChangeGroup implements VimChangeGroup {
|
||||
MotionGroup.moveCaret(editor, caret, offset);
|
||||
}
|
||||
|
||||
insertBeforeCursor(editor, context);
|
||||
insertBeforeCursor(new IjVimEditor(editor), new IjExecutionContext(context));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -926,8 +927,7 @@ public class ChangeGroup implements VimChangeGroup {
|
||||
KeyHandler.getInstance().reset(editor);
|
||||
|
||||
if (isPrintableChar(key.getKeyChar()) || activeTemplateWithLeftRightMotion(((IjVimEditor)editor).getEditor(), key)) {
|
||||
DataContext ijContext = IjExecutionContextKt.getIj(context);
|
||||
VimPlugin.getChange().insertBeforeCursor(((IjVimEditor)editor).getEditor(), ijContext);
|
||||
VimPlugin.getChange().insertBeforeCursor(editor, context);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1496,7 +1496,7 @@ public class ChangeGroup implements VimChangeGroup {
|
||||
}
|
||||
|
||||
if (visualBlockMode || !append) {
|
||||
insertBeforeCursor(editor, context);
|
||||
insertBeforeCursor(new IjVimEditor(editor), new IjExecutionContext(context));
|
||||
}
|
||||
else {
|
||||
insertAfterCursor(editor, context);
|
||||
@ -1581,7 +1581,7 @@ public class ChangeGroup implements VimChangeGroup {
|
||||
if (type == SelectionType.LINE_WISE) {
|
||||
// Please don't use `getDocument().getText().isEmpty()` because it converts CharSequence into String
|
||||
if (editor.getDocument().getTextLength() == 0) {
|
||||
insertBeforeCursor(editor, context);
|
||||
insertBeforeCursor(new IjVimEditor(editor), new IjExecutionContext(context));
|
||||
}
|
||||
else if (after && !EditorHelperRt.endsWithNewLine(editor)) {
|
||||
insertNewLineBelow(editor, caret, lp.column);
|
||||
@ -1598,7 +1598,7 @@ public class ChangeGroup implements VimChangeGroup {
|
||||
}
|
||||
}
|
||||
else {
|
||||
insertBeforeCursor(editor, context);
|
||||
insertBeforeCursor(new IjVimEditor(editor), new IjExecutionContext(context));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -34,6 +34,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.maddyhome.idea.vim.KeyHandler;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.helper.*;
|
||||
import com.maddyhome.idea.vim.newapi.IjExecutionContext;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.api.VimEditor;
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType;
|
||||
@ -222,7 +223,7 @@ public class EditorGroup implements PersistentStateComponent<Element> {
|
||||
if (!EditorHelper.isFileEditor(editor) &&
|
||||
editor.getDocument().isWritable() &&
|
||||
!CommandStateHelper.inInsertMode(editor)) {
|
||||
VimPlugin.getChange().insertBeforeCursor(editor, EditorDataContext.init(editor, null));
|
||||
VimPlugin.getChange().insertBeforeCursor(new IjVimEditor(editor), new IjExecutionContext(EditorDataContext.init(editor, null)));
|
||||
KeyHandler.getInstance().reset(new IjVimEditor(editor));
|
||||
}
|
||||
updateCaretsVisualAttributes(editor);
|
||||
|
@ -126,8 +126,8 @@ object IdeaSelectionControl {
|
||||
CommandState.Mode.SELECT -> VimPlugin.getVisualMotion()
|
||||
.enterSelectMode(editor.vim, VimPlugin.getVisualMotion().autodetectVisualSubmode(editor))
|
||||
CommandState.Mode.INSERT -> VimPlugin.getChange().insertBeforeCursor(
|
||||
editor,
|
||||
EditorDataContext.init(editor)
|
||||
editor.vim,
|
||||
EditorDataContext.init(editor).vim
|
||||
)
|
||||
CommandState.Mode.COMMAND -> Unit
|
||||
else -> error("Unexpected mode: $mode")
|
||||
|
@ -81,10 +81,6 @@ val Editor.inRepeatMode
|
||||
val Editor.inVisualMode
|
||||
get() = this.mode.inVisualMode
|
||||
|
||||
@get:JvmName("inVisualMode")
|
||||
val CommandState.Mode.inVisualMode
|
||||
get() = this == CommandState.Mode.VISUAL || this == CommandState.Mode.INSERT_VISUAL
|
||||
|
||||
@get:JvmName("inSelectMode")
|
||||
val Editor.inSelectMode
|
||||
get() = this.mode == CommandState.Mode.SELECT || this.mode == CommandState.Mode.INSERT_SELECT
|
||||
@ -113,21 +109,3 @@ val CommandState.Mode.inSingleNormalMode: Boolean
|
||||
CommandState.Mode.INSERT_NORMAL -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
fun CommandState.pushVisualMode(subMode: CommandState.SubMode, prevMode: CommandState.Mode = this.mode) {
|
||||
if (prevMode.inSingleMode) {
|
||||
popModes()
|
||||
pushModes(CommandState.Mode.INSERT_VISUAL, subMode)
|
||||
} else {
|
||||
pushModes(CommandState.Mode.VISUAL, subMode)
|
||||
}
|
||||
}
|
||||
|
||||
fun CommandState.pushSelectMode(subMode: CommandState.SubMode, prevMode: CommandState.Mode = this.mode) {
|
||||
if (prevMode.inSingleMode) {
|
||||
popModes()
|
||||
pushModes(CommandState.Mode.INSERT_SELECT, subMode)
|
||||
} else {
|
||||
pushModes(CommandState.Mode.SELECT, subMode)
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ object AppCodeTemplates {
|
||||
if (myEditor != null) {
|
||||
VimVisualTimer.doNow()
|
||||
if (myEditor.inVisualMode) {
|
||||
SelectToggleVisualMode.toggleMode(myEditor)
|
||||
SelectToggleVisualMode.toggleMode(myEditor.vim)
|
||||
KeyHandler.getInstance().partialReset(myEditor.vim)
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ object IdeaSpecifics {
|
||||
while (commandState.mode != CommandState.Mode.COMMAND) {
|
||||
commandState.popModes()
|
||||
}
|
||||
VimPlugin.getChange().insertBeforeCursor(it, dataContext)
|
||||
VimPlugin.getChange().insertBeforeCursor(it.vim, dataContext.vim)
|
||||
KeyHandler.getInstance().reset(it.vim)
|
||||
}
|
||||
}
|
||||
@ -128,7 +128,7 @@ object IdeaSpecifics {
|
||||
// Enable insert mode if there is no selection in template
|
||||
// Template with selection is handled by [com.maddyhome.idea.vim.group.visual.VisualMotionGroup.controlNonVimSelectionChange]
|
||||
if (editor.inNormalMode) {
|
||||
VimPlugin.getChange().insertBeforeCursor(editor, EditorDataContext.init(editor))
|
||||
VimPlugin.getChange().insertBeforeCursor(editor.vim, EditorDataContext.init(editor).vim)
|
||||
KeyHandler.getInstance().reset(editor.vim)
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ fun changeRange(
|
||||
vimEditor.insertText(offset.offset, indentText)
|
||||
val caretOffset = offset + indentText.length
|
||||
vimCaret.moveToOffset(caretOffset)
|
||||
VimPlugin.getChange().insertBeforeCursor(editor, context)
|
||||
VimPlugin.getChange().insertBeforeCursor(editor.vim, context.vim)
|
||||
} else {
|
||||
when (deletedInfo) {
|
||||
is OperatedRange.Characters -> {
|
||||
@ -106,7 +106,7 @@ fun changeRange(
|
||||
editor.vimChangeActionSwitchMode = CommandState.Mode.INSERT
|
||||
}
|
||||
} else {
|
||||
VimPlugin.getChange().insertBeforeCursor(editor, context)
|
||||
VimPlugin.getChange().insertBeforeCursor(editor.vim, context.vim)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,6 +92,9 @@ class IjVimCaret(val caret: Caret) : VimCaret {
|
||||
return VimVisualPosition(visualPosition.line, visualPosition.column, visualPosition.leansRight)
|
||||
}
|
||||
|
||||
override val visualLineStart: Int
|
||||
get() = caret.visualLineStart
|
||||
|
||||
override fun equals(other: Any?): Boolean = this.caret == (other as? IjVimCaret)?.caret
|
||||
|
||||
override fun hashCode(): Int = this.caret.hashCode()
|
||||
|
@ -46,6 +46,7 @@ import com.maddyhome.idea.vim.helper.exitVisualMode
|
||||
import com.maddyhome.idea.vim.helper.fileSize
|
||||
import com.maddyhome.idea.vim.helper.getTopLevelEditor
|
||||
import com.maddyhome.idea.vim.helper.inBlockSubMode
|
||||
import com.maddyhome.idea.vim.helper.isTemplateActive
|
||||
import com.maddyhome.idea.vim.helper.updateCaretsVisualAttributes
|
||||
import com.maddyhome.idea.vim.helper.updateCaretsVisualPosition
|
||||
import com.maddyhome.idea.vim.helper.vimLastSelectionType
|
||||
@ -288,6 +289,10 @@ class IjVimEditor(editor: Editor) : MutableLinearEditor() {
|
||||
editor.scrollingModel.scrollToCaret(scrollType)
|
||||
}
|
||||
|
||||
override fun isTemplateActive(): Boolean {
|
||||
return editor.isTemplateActive()
|
||||
}
|
||||
|
||||
private fun Pair<Offset, Offset>.noGuard(editor: Editor): Boolean {
|
||||
return editor.document.getRangeGuard(this.first.point, this.second.point) == null
|
||||
}
|
||||
|
@ -23,18 +23,21 @@ import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
import com.maddyhome.idea.vim.helper.exitSelectMode
|
||||
import com.maddyhome.idea.vim.helper.inBlockSubMode
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
|
||||
class SelectEscapeAction : VimActionHandler.SingleExecution() {
|
||||
|
||||
override val type: Command.Type = Command.Type.OTHER_READONLY
|
||||
|
||||
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
||||
override fun execute(
|
||||
editor: VimEditor,
|
||||
context: ExecutionContext,
|
||||
cmd: Command,
|
||||
operatorArguments: OperatorArguments,
|
||||
): Boolean {
|
||||
val blockMode = editor.inBlockSubMode
|
||||
editor.exitSelectMode(true)
|
||||
if (blockMode) editor.ij.caretModel.removeSecondaryCarets()
|
||||
editor.exitSelectModeNative(true)
|
||||
if (blockMode) editor.removeSecondaryCarets()
|
||||
return true
|
||||
}
|
||||
}
|
@ -18,21 +18,17 @@
|
||||
|
||||
package com.maddyhome.idea.vim.action.motion.select
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
import com.maddyhome.idea.vim.helper.commandState
|
||||
import com.maddyhome.idea.vim.helper.inVisualMode
|
||||
import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
|
||||
import com.maddyhome.idea.vim.helper.pushSelectMode
|
||||
import com.maddyhome.idea.vim.helper.pushVisualMode
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
|
||||
/**
|
||||
* @author Alex Plate
|
||||
@ -42,32 +38,37 @@ class SelectToggleVisualMode : VimActionHandler.SingleExecution() {
|
||||
|
||||
override val type: Command.Type = Command.Type.OTHER_READONLY
|
||||
|
||||
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
||||
toggleMode(editor.ij)
|
||||
override fun execute(
|
||||
editor: VimEditor,
|
||||
context: ExecutionContext,
|
||||
cmd: Command,
|
||||
operatorArguments: OperatorArguments,
|
||||
): Boolean {
|
||||
toggleMode(editor)
|
||||
return true
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun toggleMode(editor: Editor) {
|
||||
val commandState = editor.vim.commandState
|
||||
fun toggleMode(editor: VimEditor) {
|
||||
val commandState = editor.commandState
|
||||
val subMode = commandState.subMode
|
||||
val mode = commandState.mode
|
||||
commandState.popModes()
|
||||
if (mode.inVisualMode) {
|
||||
commandState.pushSelectMode(subMode, mode)
|
||||
if (subMode != CommandState.SubMode.VISUAL_LINE) {
|
||||
editor.caretModel.runForEachCaret {
|
||||
if (it.offset + VimPlugin.getVisualMotion().selectionAdj == it.selectionEnd) {
|
||||
it.moveToInlayAwareOffset(it.offset + VimPlugin.getVisualMotion().selectionAdj)
|
||||
editor.nativeCarets().forEach {
|
||||
if (it.offset.point + injector.visualMotionGroup.selectionAdj == it.selectionEnd) {
|
||||
it.moveToInlayAwareOffset(it.offset.point + injector.visualMotionGroup.selectionAdj)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
commandState.pushVisualMode(subMode, mode)
|
||||
if (subMode != CommandState.SubMode.VISUAL_LINE) {
|
||||
editor.caretModel.runForEachCaret {
|
||||
if (it.offset == it.selectionEnd && it.visualLineStart <= it.offset - VimPlugin.getVisualMotion().selectionAdj) {
|
||||
it.moveToInlayAwareOffset(it.offset - VimPlugin.getVisualMotion().selectionAdj)
|
||||
editor.nativeCarets().forEach {
|
||||
if (it.offset.point == it.selectionEnd && it.visualLineStart <= it.offset.point - injector.visualMotionGroup.selectionAdj) {
|
||||
it.moveToInlayAwareOffset(it.offset.point - injector.visualMotionGroup.selectionAdj)
|
||||
}
|
||||
}
|
||||
}
|
@ -18,11 +18,10 @@
|
||||
|
||||
package com.maddyhome.idea.vim.action.motion.select.motion
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.VimCaret
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.MotionType
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
@ -30,9 +29,6 @@ import com.maddyhome.idea.vim.handler.Motion
|
||||
import com.maddyhome.idea.vim.handler.MotionActionHandler
|
||||
import com.maddyhome.idea.vim.handler.toMotion
|
||||
import com.maddyhome.idea.vim.handler.toMotionOrError
|
||||
import com.maddyhome.idea.vim.helper.exitSelectMode
|
||||
import com.maddyhome.idea.vim.helper.isTemplateActive
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.options.OptionConstants
|
||||
import com.maddyhome.idea.vim.options.OptionScope
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
|
||||
@ -52,25 +48,27 @@ class SelectMotionLeftAction : MotionActionHandler.ForEachCaret() {
|
||||
argument: Argument?,
|
||||
operatorArguments: OperatorArguments,
|
||||
): Motion {
|
||||
val keymodel = (VimPlugin.getOptionService().getOptionValue(OptionScope.GLOBAL, OptionConstants.keymodelName) as VimString).value
|
||||
val keymodel =
|
||||
(injector.optionService.getOptionValue(OptionScope.GLOBAL, OptionConstants.keymodelName) as VimString).value
|
||||
if (OptionConstants.keymodel_stopsel in keymodel || OptionConstants.keymodel_stopselect in keymodel) {
|
||||
logger.debug("Keymodel option has stopselect. Exiting select mode")
|
||||
val startSelection = caret.ij.selectionStart
|
||||
val endSelection = caret.ij.selectionEnd
|
||||
editor.exitSelectMode(false)
|
||||
if (editor.ij.isTemplateActive()) {
|
||||
val startSelection = caret.selectionStart
|
||||
val endSelection = caret.selectionEnd
|
||||
editor.exitSelectModeNative(false)
|
||||
if (editor.isTemplateActive()) {
|
||||
logger.debug("Template is active. Activate insert mode")
|
||||
VimPlugin.getChange().insertBeforeCursor(editor.ij, context.ij)
|
||||
injector.changeGroup.insertBeforeCursor(editor, context)
|
||||
if (caret.offset.point in startSelection..endSelection) {
|
||||
return startSelection.toMotion()
|
||||
}
|
||||
}
|
||||
// No return statement, perform motion to left
|
||||
}
|
||||
return VimPlugin.getMotion().getOffsetOfHorizontalMotion(editor, caret, -operatorArguments.count1, false).toMotionOrError()
|
||||
return injector.motion.getOffsetOfHorizontalMotion(editor, caret, -operatorArguments.count1, false)
|
||||
.toMotionOrError()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val logger = Logger.getInstance(SelectMotionLeftAction::class.java)
|
||||
private val logger = injector.getLogger(SelectMotionLeftAction::class.java)
|
||||
}
|
||||
}
|
@ -18,11 +18,10 @@
|
||||
|
||||
package com.maddyhome.idea.vim.action.motion.select.motion
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.VimCaret
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.MotionType
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
@ -30,9 +29,6 @@ import com.maddyhome.idea.vim.handler.Motion
|
||||
import com.maddyhome.idea.vim.handler.MotionActionHandler
|
||||
import com.maddyhome.idea.vim.handler.toMotion
|
||||
import com.maddyhome.idea.vim.handler.toMotionOrError
|
||||
import com.maddyhome.idea.vim.helper.exitSelectMode
|
||||
import com.maddyhome.idea.vim.helper.isTemplateActive
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.options.OptionConstants
|
||||
import com.maddyhome.idea.vim.options.OptionScope
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
|
||||
@ -52,25 +48,26 @@ class SelectMotionRightAction : MotionActionHandler.ForEachCaret() {
|
||||
argument: Argument?,
|
||||
operatorArguments: OperatorArguments,
|
||||
): Motion {
|
||||
val keymodel = (VimPlugin.getOptionService().getOptionValue(OptionScope.GLOBAL, OptionConstants.keymodelName) as VimString).value
|
||||
val keymodel =
|
||||
(injector.optionService.getOptionValue(OptionScope.GLOBAL, OptionConstants.keymodelName) as VimString).value
|
||||
if (OptionConstants.keymodel_stopsel in keymodel || OptionConstants.keymodel_stopselect in keymodel) {
|
||||
logger.debug("Keymodel option has stopselect. Exiting select mode")
|
||||
val startSelection = caret.ij.selectionStart
|
||||
val endSelection = caret.ij.selectionEnd
|
||||
editor.exitSelectMode(false)
|
||||
if (editor.ij.isTemplateActive()) {
|
||||
val startSelection = caret.selectionStart
|
||||
val endSelection = caret.selectionEnd
|
||||
editor.exitSelectModeNative(false)
|
||||
if (editor.isTemplateActive()) {
|
||||
logger.debug("Template is active. Activate insert mode")
|
||||
VimPlugin.getChange().insertBeforeCursor(editor.ij, context.ij)
|
||||
injector.changeGroup.insertBeforeCursor(editor, context)
|
||||
if (caret.offset.point in startSelection..endSelection) {
|
||||
return endSelection.toMotion()
|
||||
}
|
||||
}
|
||||
return caret.offset.point.toMotion()
|
||||
}
|
||||
return VimPlugin.getMotion().getOffsetOfHorizontalMotion(editor, caret, operatorArguments.count1, false).toMotionOrError()
|
||||
return injector.motion.getOffsetOfHorizontalMotion(editor, caret, operatorArguments.count1, false).toMotionOrError()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val logger = Logger.getInstance(SelectMotionRightAction::class.java)
|
||||
private val logger = injector.getLogger(SelectMotionRightAction::class.java)
|
||||
}
|
||||
}
|
@ -21,4 +21,5 @@ interface VimCaret {
|
||||
fun moveToInlayAwareOffset(newOffset: Int)
|
||||
fun vimSetSelection(start: Int, end: Int = start, moveCaretToSelectionEnd: Boolean = false)
|
||||
fun getVisualPosition(): VimVisualPosition
|
||||
val visualLineStart: Int
|
||||
}
|
@ -21,7 +21,8 @@ import com.maddyhome.idea.vim.command.Command
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
interface VimChangeGroup {
|
||||
fun processCommand(editor: VimEditor, cmd: Command)
|
||||
fun processKey(editor: VimEditor, context: ExecutionContext, key: KeyStroke): Boolean
|
||||
fun processKeyInSelectMode(editor: VimEditor, context: ExecutionContext, key: KeyStroke): Boolean
|
||||
fun processCommand(editor: VimEditor, cmd: Command)
|
||||
fun processKey(editor: VimEditor, context: ExecutionContext, key: KeyStroke): Boolean
|
||||
fun processKeyInSelectMode(editor: VimEditor, context: ExecutionContext, key: KeyStroke): Boolean
|
||||
fun insertBeforeCursor(editor: VimEditor, context: ExecutionContext)
|
||||
}
|
@ -196,6 +196,7 @@ interface VimEditor {
|
||||
var vimLastSelectionType: SelectionType?
|
||||
|
||||
fun scrollToCaret(type: VimScrollType)
|
||||
fun isTemplateActive(): Boolean
|
||||
}
|
||||
|
||||
interface MutableVimEditor : VimEditor {
|
||||
|
@ -110,3 +110,12 @@ fun CommandState.pushSelectMode(subMode: CommandState.SubMode, prevMode: Command
|
||||
pushModes(CommandState.Mode.SELECT, subMode)
|
||||
}
|
||||
}
|
||||
|
||||
fun CommandState.pushVisualMode(subMode: CommandState.SubMode, prevMode: CommandState.Mode = this.mode) {
|
||||
if (prevMode.inSingleMode) {
|
||||
popModes()
|
||||
pushModes(CommandState.Mode.INSERT_VISUAL, subMode)
|
||||
} else {
|
||||
pushModes(CommandState.Mode.VISUAL, subMode)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user