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:
parent
5c18dd0603
commit
6a6632e363
src/com/maddyhome/idea/vim/extension/commentary
test/org/jetbrains/plugins/ideavim/extension/commentary
@ -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) {
|
||||
|
@ -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|
|
||||
|
Loading…
Reference in New Issue
Block a user