mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-03-07 21:32:52 +01:00
Remove FLAG_FORCE_LINEWISE and FLAG_FORCE_VISUAL flags
This commit is contained in:
parent
4eacdeec5e
commit
7be884b138
src/com/maddyhome/idea/vim
action/change/change
command
group
handler
listener
@ -26,8 +26,8 @@ import com.maddyhome.idea.vim.action.VimCommandAction;
|
||||
import com.maddyhome.idea.vim.command.Command;
|
||||
import com.maddyhome.idea.vim.command.CommandFlags;
|
||||
import com.maddyhome.idea.vim.command.MappingMode;
|
||||
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler;
|
||||
import com.maddyhome.idea.vim.group.visual.VimSelection;
|
||||
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@ -73,6 +73,6 @@ public class AutoIndentLinesVisualAction extends VimCommandAction {
|
||||
|
||||
@Override
|
||||
public EnumSet<CommandFlags> getFlags() {
|
||||
return EnumSet.of(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_FORCE_LINEWISE, CommandFlags.FLAG_EXIT_VISUAL);
|
||||
return EnumSet.of(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_EXIT_VISUAL);
|
||||
}
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ import com.maddyhome.idea.vim.action.VimCommandAction;
|
||||
import com.maddyhome.idea.vim.command.Command;
|
||||
import com.maddyhome.idea.vim.command.CommandFlags;
|
||||
import com.maddyhome.idea.vim.command.MappingMode;
|
||||
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler;
|
||||
import com.maddyhome.idea.vim.group.visual.VimSelection;
|
||||
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@ -73,6 +73,6 @@ public class ReformatCodeVisualAction extends VimCommandAction {
|
||||
|
||||
@Override
|
||||
public EnumSet<CommandFlags> getFlags() {
|
||||
return EnumSet.of(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_FORCE_LINEWISE, CommandFlags.FLAG_EXIT_VISUAL);
|
||||
return EnumSet.of(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_EXIT_VISUAL);
|
||||
}
|
||||
}
|
||||
|
@ -66,8 +66,6 @@ enum class CommandFlags {
|
||||
* Command exits the visual mode, so caret movement shouldn't update visual selection
|
||||
*/
|
||||
FLAG_EXIT_VISUAL,
|
||||
FLAG_FORCE_VISUAL,
|
||||
FLAG_FORCE_LINEWISE,
|
||||
/**
|
||||
* Special flag used for any mappings involving operators
|
||||
*/
|
||||
|
@ -25,6 +25,7 @@ import com.intellij.codeInsight.template.TemplateManager;
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.command.UndoConfirmationPolicy;
|
||||
@ -1419,17 +1420,18 @@ public class ChangeGroup {
|
||||
/**
|
||||
* Deletes the range of text and enters insert mode
|
||||
*
|
||||
* @param editor The editor to change
|
||||
* @param caret The caret to be moved after range deletion
|
||||
* @param range The range to change
|
||||
* @param type The type of the range
|
||||
* @param editor The editor to change
|
||||
* @param caret The caret to be moved after range deletion
|
||||
* @param range The range to change
|
||||
* @param type The type of the range
|
||||
* @param context
|
||||
* @return true if able to delete the range, false if not
|
||||
*/
|
||||
public boolean changeRange(@NotNull Editor editor,
|
||||
@NotNull Caret caret,
|
||||
@NotNull TextRange range,
|
||||
@NotNull SelectionType type, DataContext context) {
|
||||
@NotNull SelectionType type,
|
||||
DataContext context) {
|
||||
int col = 0;
|
||||
int lines = 0;
|
||||
if (type == SelectionType.BLOCK_WISE) {
|
||||
@ -1449,7 +1451,8 @@ public class ChangeGroup {
|
||||
if (type == SelectionType.LINE_WISE) {
|
||||
if (editor.getDocument().getText().isEmpty()) {
|
||||
insertBeforeCursor(editor, context);
|
||||
} else if (after) {
|
||||
}
|
||||
else if (after) {
|
||||
insertNewLineBelow(editor, caret, lp.column);
|
||||
}
|
||||
else {
|
||||
@ -1498,7 +1501,7 @@ public class ChangeGroup {
|
||||
}
|
||||
|
||||
public void reformatCode(@NotNull DataContext context) {
|
||||
KeyHandler.executeAction("ReformatCode", context);
|
||||
KeyHandler.executeAction(IdeActions.ACTION_EDITOR_REFORMAT, context);
|
||||
}
|
||||
|
||||
public void autoIndentMotion(@NotNull Editor editor,
|
||||
@ -1522,7 +1525,7 @@ public class ChangeGroup {
|
||||
|
||||
VisualUtilKt.vimSetSystemSelectionSilently(editor.getSelectionModel(), startOffset, endOffset);
|
||||
|
||||
KeyHandler.executeAction("AutoIndentLines", context);
|
||||
KeyHandler.executeAction(IdeActions.ACTION_EDITOR_AUTO_INDENT_LINES, context);
|
||||
|
||||
final int firstLine = editor.offsetToLogicalPosition(Math.min(startOffset, endOffset)).line;
|
||||
final int newOffset = VimPlugin.getMotion().moveCaretToLineStartSkipLeading(editor, firstLine);
|
||||
@ -1598,7 +1601,8 @@ public class ChangeGroup {
|
||||
|
||||
final int sline = editor.offsetToLogicalPosition(range.getStartOffset()).line;
|
||||
final LogicalPosition endLogicalPosition = editor.offsetToLogicalPosition(range.getEndOffset());
|
||||
final int eline = endLogicalPosition.column == 0 ? Math.max(endLogicalPosition.line - 1, 0) : endLogicalPosition.line;
|
||||
final int eline =
|
||||
endLogicalPosition.column == 0 ? Math.max(endLogicalPosition.line - 1, 0) : endLogicalPosition.line;
|
||||
|
||||
if (range.isMultiple()) {
|
||||
final int from = editor.offsetToLogicalPosition(range.getStartOffset()).column;
|
||||
@ -1682,7 +1686,9 @@ public class ChangeGroup {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type == null || CommandState.inInsertMode(editor) || VimPlugin.getRegister().storeText(editor, range, type, true)) {
|
||||
if (type == null ||
|
||||
CommandState.inInsertMode(editor) ||
|
||||
VimPlugin.getRegister().storeText(editor, range, type, true)) {
|
||||
final Document document = editor.getDocument();
|
||||
final int[] startOffsets = range.getStartOffsets();
|
||||
final int[] endOffsets = range.getEndOffsets();
|
||||
|
@ -149,56 +149,30 @@ sealed class VisualOperatorActionHandler : EditorActionHandlerBase(false) {
|
||||
}
|
||||
|
||||
protected class VisualStartFinishWrapper(private val editor: Editor, private val cmd: Command) {
|
||||
private lateinit var lastMode: CommandState.SubMode
|
||||
private val visualChanges = mutableMapOf<Caret, VisualChange?>()
|
||||
|
||||
private fun startForCaret(caret: Caret) {
|
||||
val change = if (CommandState.inVisualMode(editor) && !CommandState.inRepeatMode(editor)) {
|
||||
VisualOperation.getRange(editor, caret, cmd.flags)
|
||||
} else null
|
||||
logger.info("visual change = $change")
|
||||
visualChanges[caret] = change
|
||||
}
|
||||
|
||||
fun start() {
|
||||
logger.debug("start")
|
||||
EditorData.setKeepingVisualOperatorAction(editor, CommandFlags.FLAG_EXIT_VISUAL !in cmd.flags)
|
||||
|
||||
editor.vimForAllOrPrimaryCaret(this@VisualStartFinishWrapper::startForCaret)
|
||||
editor.vimForAllOrPrimaryCaret {
|
||||
val change = if (CommandState.inVisualMode(this@VisualStartFinishWrapper.editor) && !CommandState.inRepeatMode(this@VisualStartFinishWrapper.editor)) {
|
||||
VisualOperation.getRange(this@VisualStartFinishWrapper.editor, it, this@VisualStartFinishWrapper.cmd.flags)
|
||||
} else null
|
||||
logger.info("visual change = $change")
|
||||
this@VisualStartFinishWrapper.visualChanges[it] = change
|
||||
}
|
||||
|
||||
// If this is a mutli key change then exit visual now
|
||||
if (CommandFlags.FLAG_MULTIKEY_UNDO in cmd.flags) {
|
||||
logger.debug("multikey undo - exit visual")
|
||||
if (CommandFlags.FLAG_MULTIKEY_UNDO in cmd.flags || CommandFlags.FLAG_EXIT_VISUAL in cmd.flags) {
|
||||
logger.debug("Exit visual")
|
||||
VimPlugin.getVisualMotion().exitVisual(editor)
|
||||
} else if (CommandFlags.FLAG_FORCE_LINEWISE in cmd.flags) {
|
||||
lastMode = CommandState.getInstance(editor).subMode
|
||||
if (lastMode != CommandState.SubMode.VISUAL_LINE && CommandFlags.FLAG_FORCE_VISUAL in cmd.flags) {
|
||||
VimPlugin.getVisualMotion().toggleVisual(editor, 1, 0, CommandState.SubMode.VISUAL_LINE)
|
||||
}
|
||||
}
|
||||
|
||||
if (CommandFlags.FLAG_EXIT_VISUAL in cmd.flags) {
|
||||
VimPlugin.getVisualMotion().exitVisual(editor)
|
||||
}
|
||||
}
|
||||
|
||||
private fun finishForCaret(caret: Caret, res: Boolean) {
|
||||
if (res) {
|
||||
visualChanges[caret]?.let {
|
||||
caret.vimLastVisualOperatorRange = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun finish(res: Boolean) {
|
||||
logger.debug("finish")
|
||||
|
||||
if (CommandFlags.FLAG_FORCE_LINEWISE in cmd.flags) {
|
||||
if (this::lastMode.isInitialized && lastMode != CommandState.SubMode.VISUAL_LINE && CommandFlags.FLAG_FORCE_VISUAL in cmd.flags) {
|
||||
VimPlugin.getVisualMotion().toggleVisual(editor, 1, 0, lastMode)
|
||||
}
|
||||
}
|
||||
|
||||
if (CommandFlags.FLAG_MULTIKEY_UNDO !in cmd.flags && CommandFlags.FLAG_EXPECT_MORE !in cmd.flags) {
|
||||
logger.debug("not multikey undo - exit visual")
|
||||
VimPlugin.getVisualMotion().exitVisual(editor)
|
||||
@ -206,10 +180,7 @@ sealed class VisualOperatorActionHandler : EditorActionHandlerBase(false) {
|
||||
|
||||
if (res) {
|
||||
CommandState.getInstance(editor).saveLastChangeCommand(cmd)
|
||||
}
|
||||
|
||||
for (caret in editor.caretModel.allCarets) {
|
||||
finishForCaret(caret, res)
|
||||
editor.vimForAllOrPrimaryCaret { caret -> visualChanges[caret]?.let { caret.vimLastVisualOperatorRange = it } }
|
||||
}
|
||||
|
||||
EditorData.setKeepingVisualOperatorAction(editor, false)
|
||||
|
@ -69,7 +69,7 @@ import java.io.Closeable
|
||||
*
|
||||
* java
|
||||
* ```
|
||||
* try (SelectionVimListenerSuppressor ignored = SelectionVimListenerSuppressor.INSTANCE.lock()) {
|
||||
* try (final VimListenerSuppressor ignored = SelectionVimListenerSuppressor.INSTANCE.lock()) {
|
||||
* ....
|
||||
* }
|
||||
* ```
|
||||
|
Loading…
Reference in New Issue
Block a user