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

Fix motion down

This commit is contained in:
Alex Plate 2019-03-22 21:02:37 +03:00
parent 826b3d6803
commit 5be2ca8efc
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
3 changed files with 48 additions and 45 deletions
src/com/maddyhome/idea/vim
action/motion/updown
helper
test/org/jetbrains/plugins/ideavim/action/motion/updown

View File

@ -21,15 +21,12 @@ package com.maddyhome.idea.vim.action.motion.updown;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.VisualPosition;
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.action.motion.MotionEditorAction;
import com.maddyhome.idea.vim.command.Argument;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.handler.MotionEditorActionHandler;
import com.maddyhome.idea.vim.helper.CaretDataKt;
import com.maddyhome.idea.vim.helper.EditorData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -53,20 +50,6 @@ public class MotionDownAction extends MotionEditorAction {
int count,
int rawCount,
@Nullable Argument argument) {
if (CommandState.inVisualBlockMode(editor) && EditorData.shouldIgnoreNextMove(editor)) {
EditorData.dontIgnoreNextMove(editor);
return caret.getOffset();
}
if (CommandState.inVisualBlockMode(editor)) {
int blockEndOffset = CaretDataKt.getVimSelectionStart(caret);
int blockStartOffset = caret.getOffset();
VisualPosition blockEndPosition = editor.offsetToVisualPosition(blockEndOffset);
VisualPosition blockStartPosition = editor.offsetToVisualPosition(blockStartOffset);
if (blockEndPosition.getLine() < blockStartPosition.getLine()) {
EditorData.ignoreNextMove(editor);
}
}
return VimPlugin.getMotion().moveCaretVertical(editor, caret, count);
}

View File

@ -169,33 +169,6 @@ public class EditorData {
return FileDocumentManager.getInstance().getFile(editor.getDocument());
}
/**
* Asks whether next down move should be ignored.
*/
public static boolean shouldIgnoreNextMove(@NotNull Editor editor) {
Boolean ret = editor.getUserData(IGNORE_NEXT_MOVE);
if (ret == null) {
return false;
}
else {
return ret;
}
}
/**
* Indicate that the next down move should be ignored.
*/
public static void ignoreNextMove(@NotNull Editor editor) {
editor.putUserData(IGNORE_NEXT_MOVE, true);
}
/**
* Indicate that the next down move should not be ignored.
*/
public static void dontIgnoreNextMove(@NotNull Editor editor) {
editor.putUserData(IGNORE_NEXT_MOVE, false);
}
/**
* Checks whether a keeping visual mode visual operator action is performed on editor.
*/
@ -265,7 +238,6 @@ public class EditorData {
private static final Key<ExOutputPanel> MORE_PANEL = new Key<ExOutputPanel>("IdeaVim.morePanel");
private static final Key<ExOutputModel> EX_OUTPUT_MODEL = new Key<ExOutputModel>("IdeaVim.exOutputModel");
private static final Key<TestInputModel> TEST_INPUT_MODEL = new Key<TestInputModel>("IdeaVim.testInputModel");
private static final Key<Boolean> IGNORE_NEXT_MOVE = new Key<>("shouldIgnoreNextMove");
private static final Key<Boolean> IS_KEEPING_VISUAL_OPERATOR_ACTION = new Key<>("isKeepingVisualOperatorAction");
private static final Key<CommandState.Mode> CHANGE_ACTION_SWITCH_MODE = new Key<>("changeActionSwitchMode");
private static final Key<Boolean> WAS_VISUAL_BLOCK_MODE = new Key<>("wasVisualBlockMode");

View File

@ -0,0 +1,48 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2019 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.jetbrains.plugins.ideavim.action.motion.updown
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
import org.jetbrains.plugins.ideavim.VimTestCase
/**
* @author Alex Plate
*/
class MotionDownActionTest : VimTestCase() {
fun `test motion down in visual block mode`() {
val keys = parseKeys("<C-V>2kjjj")
val before = """
A Discovery
I |found| it in a legendary land
al|l roc|ks and lavender and tufted grass,
wh|<caret>ere i|t was settled on some sodden sand
ha|rd by| the torrent of a mountain pass.
""".trimIndent()
val after = """
A Discovery
I |found| it in a legendary land
al|l roc|ks and lavender and tufted grass,
wh|<selection>e</selection>re i|t was settled on some sodden sand
ha|<selection>r</selection>d by| the torrent of a mountain pass.
""".trimIndent()
doTest(keys, before, after)
}
}