1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-08-01 15:59:06 +02:00

Merge remote-tracking branch 'ikenox/feature/action-in-visual-mode'

This commit is contained in:
Andrey Vlasovskikh 2017-12-15 01:37:40 +03:00
commit c0410131bf
2 changed files with 54 additions and 4 deletions
src/com/maddyhome/idea/vim/ex/handler
test/org/jetbrains/plugins/ideavim/ex

View File

@ -37,7 +37,7 @@ import org.jetbrains.annotations.NotNull;
*/
public class ActionHandler extends CommandHandler {
public ActionHandler() {
super("action", "", RANGE_FORBIDDEN | DONT_REOPEN);
super("action", "", RANGE_OPTIONAL | DONT_REOPEN);
}
public boolean execute(@NotNull Editor editor, @NotNull final DataContext context,
@ -50,20 +50,24 @@ public class ActionHandler extends CommandHandler {
}
final Application application = ApplicationManager.getApplication();
if (application.isUnitTestMode()) {
executeAction(action, context, actionName);
executeAction(editor, cmd,action, context, actionName);
}
else {
UiHelper.runAfterGotFocus(new Runnable() {
@Override
public void run() {
executeAction(action, context, actionName);
executeAction(editor, cmd, action, context, actionName);
}
});
}
return true;
}
private void executeAction(@NotNull AnAction action, @NotNull DataContext context, @NotNull String actionName) {
private void executeAction(@NotNull Editor editor, @NotNull ExCommand cmd, @NotNull AnAction action,
@NotNull DataContext context, @NotNull String actionName) {
if (cmd.getRanges().size() > 0) {
VimPlugin.getMotion().swapVisualSelections(editor);
}
try {
KeyHandler.executeAction(action, context);
}

View File

@ -8,6 +8,7 @@ import static com.maddyhome.idea.vim.helper.StringHelper.parseKeys;
/**
* @author vlan
*/
public class VariousCommandsTest extends VimTestCase {
// VIM-550 |:put|
public void testPutCreatesNewLine() {
@ -38,4 +39,49 @@ public class VariousCommandsTest extends VimTestCase {
myFixture.checkResult("f<caret>oo\n" +
"bar\n");
}
// VIM-862 |:action| in visual character mode
public void testExCommandInVisualCharacterMode() {
configureByJavaText("-----\n" +
"1<caret>2345\n" +
"abcde\n" +
"-----");
typeText(parseKeys("vjl"));
typeText(commandToKeys("'<,'>action CommentByBlockComment"));
assertMode(CommandState.Mode.COMMAND);
myFixture.checkResult("-----\n" +
"1/*2345\n" +
"abc*/de\n" +
"-----");
}
// VIM-862 |:action| in visual line mode
public void testExCommandInVisualLineMode() {
configureByJavaText("-----\n" +
"1<caret>2345\n" +
"abcde\n" +
"-----");
typeText(parseKeys("Vj"));
typeText(commandToKeys("'<,'>action CommentByBlockComment"));
assertMode(CommandState.Mode.COMMAND);
myFixture.checkResult("-----\n" +
"/*12345\n" +
"abcde*/\n" +
"-----");
}
// VIM-862 |:action| in visual block mode
public void testExCommandInVisualBlockMode() {
configureByJavaText("-----\n" +
"1<caret>2345\n" +
"abcde\n" +
"-----");
typeText(parseKeys("<C-V>lj"));
typeText(commandToKeys("'<,'>action CommentByBlockComment"));
assertMode(CommandState.Mode.COMMAND);
myFixture.checkResult("-----\n" +
"1/*23*/45\n" +
"a/*bc*/de\n" +
"-----");
}
}