1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-08-14 17:17:07 +02:00

Disable new api for o commands

This commit is contained in:
Alex Plate
2022-01-25 10:28:23 +03:00
parent 9484599bfd
commit 42ec2b9dce
3 changed files with 46 additions and 13 deletions
src/main/java/com/maddyhome/idea/vim

@@ -26,7 +26,6 @@ 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.helper.experimentalApi
import com.maddyhome.idea.vim.newapi.insertLineAround
import java.util.*
@@ -42,7 +41,9 @@ class InsertNewLineBelowAction : ChangeEditorActionHandler.SingleExecution() {
operatorArguments: OperatorArguments,
): Boolean {
if (editor.isOneLineMode) return false
if (experimentalApi()) {
// if (experimentalApi()) {
@Suppress("ConstantConditionIf")
if (false) {
insertLineAround(editor, context, 1)
} else {
VimPlugin.getChange().insertNewLineBelow(editor, context)
@@ -63,7 +64,9 @@ class InsertNewLineAboveAction : ChangeEditorActionHandler.SingleExecution() {
operatorArguments: OperatorArguments,
): Boolean {
if (editor.isOneLineMode) return false
if (experimentalApi()) {
// if (experimentalApi()) {
@Suppress("ConstantConditionIf")
if (false) {
insertLineAround(editor, context, 0)
} else {
VimPlugin.getChange().insertNewLineAbove(editor, context)

@@ -171,12 +171,15 @@ public class ChangeGroup {
if (editor.isOneLineMode()) return;
// See also EditorStartNewLineBefore. That will move the caret to line start, call EditorEnter to create a new line,
// and then move up and call EditorLineEnd. We get better indent positioning by going to the line end of the
// previous line and hitting enter, especially with plain text files.
// and then move up and call EditorLineEnd. We get better indent positioning by going to the line end of the
// previous line and hitting enter, especially with plain text files.
// However, we'll use EditorStartNewLineBefore in PyCharm notebooks where the last character of the previous line
// may be locked with a guard
// Note that we're deliberately bypassing MotionGroup.moveCaret to avoid side effects, most notably unncessary
// scrolling
Set<Caret> firstLiners = new HashSet<>();
Set<Pair<Caret, Integer>> moves = new HashSet<>();
for (Caret caret : editor.getCaretModel().getAllCarets()) {
final int offset;
if (caret.getVisualPosition().line == 0) {
@@ -187,17 +190,29 @@ public class ChangeGroup {
else {
offset = VimPlugin.getMotion().moveCaretToLineEnd(editor, caret.getLogicalPosition().line - 1, true);
}
caret.moveToOffset(offset);
moves.add(new Pair<>(caret, offset));
}
initInsert(editor, context, CommandState.Mode.INSERT);
runEnterAction(editor, context);
for (Caret caret : editor.getCaretModel().getAllCarets()) {
if (firstLiners.contains(caret)) {
final int offset = VimPlugin.getMotion().moveCaretToLineEnd(editor, 0, true);
MotionGroup.moveCaret(editor, caret, offset);
// Check if the "last character on previous line" has a guard
// This is actively used in pycharm notebooks https://youtrack.jetbrains.com/issue/VIM-2495
boolean hasGuards = moves.stream().anyMatch(it -> editor.getDocument().getOffsetGuard(it.getSecond()) != null);
if (!hasGuards) {
for (Pair<Caret, Integer> move : moves) {
move.getFirst().moveToOffset(move.getSecond());
}
initInsert(editor, context, CommandState.Mode.INSERT);
runEnterAction(editor, context);
for (Caret caret : editor.getCaretModel().getAllCarets()) {
if (firstLiners.contains(caret)) {
final int offset = VimPlugin.getMotion().moveCaretToLineEnd(editor, 0, true);
MotionGroup.moveCaret(editor, caret, offset);
}
}
} else {
initInsert(editor, context, CommandState.Mode.INSERT);
runEnterAboveAction(editor, context);
}
MotionGroup.scrollCaretIntoView(editor);
@@ -278,6 +293,19 @@ public class ChangeGroup {
}
}
private void runEnterAboveAction(Editor editor, @NotNull DataContext context) {
CommandState state = CommandState.getInstance(editor);
if (!state.isDotRepeatInProgress()) {
// While repeating the enter action has been already executed because `initInsert` repeats the input
final ActionManager actionManager = ActionManager.getInstance();
final AnAction action = actionManager.getAction("EditorStartNewLineBefore");
if (action != null) {
strokes.add(action);
KeyHandler.executeAction(action, context);
}
}
}
/**
* Begin insert at the location of the previous insert
*

@@ -135,6 +135,8 @@ fun deleteRange(
}
/**
* XXX: This implementation is incorrect!
*
* Known issues of this code:
* - Indent is incorrect when `o` for kotlin code like
* ```