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

Fix visual-mode gc action

This commit is contained in:
dhleong 2016-05-14 18:32:15 -04:00 committed by Daniel Leong
parent 5c18dd0603
commit 6a6632e363
2 changed files with 42 additions and 1 deletions
src/com/maddyhome/idea/vim/extension/commentary
test/org/jetbrains/plugins/ideavim/extension/commentary

View File

@ -37,7 +37,7 @@ public class CommentaryExtension extends VimNonDisposableExtension {
protected void initOnce() {
putExtensionHandlerMapping(MappingMode.N, parseKeys("<Plug>(CommentMotion)"), new CommentMotionHandler(), false);
putExtensionHandlerMapping(MappingMode.N, parseKeys("<Plug>(CommentLine)"), new CommentLineHandler(), false);
putExtensionHandlerMapping(MappingMode.VO, parseKeys("<Plug>(CommentMotionV)"), new CommentMotionHandler(), false);
putExtensionHandlerMapping(MappingMode.VO, parseKeys("<Plug>(CommentMotionV)"), new CommentMotionVHandler(), false);
putKeyMapping(MappingMode.N, parseKeys("gc"), parseKeys("<Plug>(CommentMotion)"), true);
putKeyMapping(MappingMode.N, parseKeys("gcc"), parseKeys("<Plug>(CommentLine)"), true);
@ -52,6 +52,26 @@ public class CommentaryExtension extends VimNonDisposableExtension {
}
}
private static class CommentMotionVHandler implements VimExtensionHandler {
@Override
public void execute(@NotNull Editor editor, @NotNull DataContext context) {
final TextRange visualRange = VimPlugin.getMark().getVisualSelectionMarks(editor);
if (visualRange == null) {
return;
}
// always use line-wise comments
if (!new Operator().apply(editor, context, SelectionType.LINE_WISE)) {
return;
}
// Leave visual mode
executeNormal(parseKeys("<Esc>"), editor);
editor.getCaretModel().moveToOffset(visualRange.getStartOffset());
}
}
private static class Operator implements OperatorFunction {
@Override
public boolean apply(@NotNull Editor editor, @NotNull DataContext context, @NotNull SelectionType selectionType) {

View File

@ -96,6 +96,27 @@ public class CommentaryExtensionTest extends JavaVimTestCase {
"if (condition) {}");
}
/* Visual mode */
// |gc| |ip|
public void testLineCommentVisualInnerParagraph() {
doTest(parseKeys("vipgc"),
"<caret>if (condition) {\n" + "}\n",
"//if (condition) {\n" +
"//}\n");
}
// |gc| |ip|
public void testLineUncommentVisualInnerParagraph() {
doTest(parseKeys("vipgc"),
"<caret>//if (condition) {\n" + "//}\n",
"if (condition) {\n" +
"}\n");
}
/* Special shortcut gcc is always linewise */
// |gcc|