1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-03-01 13:46:02 +01:00

Implement gcc as gc_ motion

gcc now respects count

Fixes VIM-1687
This commit is contained in:
Matt Ellis 2022-04-08 16:50:10 +01:00
parent feae15c48c
commit cc029fc98e
No known key found for this signature in database
GPG Key ID: FA6025D54131324B
2 changed files with 23 additions and 14 deletions
src
main/java/com/maddyhome/idea/vim/extension/commentary
test/java/org/jetbrains/plugins/ideavim/extension/commentary

View File

@ -45,7 +45,7 @@ class CommentaryExtension : VimExtension {
override fun init() {
putExtensionHandlerMapping(MappingMode.N, parseKeys("<Plug>Commentary"), owner, CommentMotionHandler(), false)
putExtensionHandlerMapping(MappingMode.XO, parseKeys("<Plug>Commentary"), owner, CommentMotionVHandler(), false)
putExtensionHandlerMapping(MappingMode.N, parseKeys("<Plug>CommentaryLine"), owner, CommentLineHandler(), false)
putKeyMappingIfMissing(MappingMode.N, parseKeys("<Plug>CommentaryLine"), owner, parseKeys("gc_"), true)
putKeyMappingIfMissing(MappingMode.N, parseKeys("gc"), owner, parseKeys("<Plug>Commentary"), true)
putKeyMappingIfMissing(MappingMode.XO, parseKeys("gc"), owner, parseKeys("<Plug>Commentary"), true)
@ -61,19 +61,6 @@ class CommentaryExtension : VimExtension {
}
}
private class CommentLineHandler : VimExtensionHandler {
override fun isRepeatable() = true
override fun execute(editor: Editor, context: DataContext) {
val offset = editor.caretModel.offset
val line = editor.document.getLineNumber(offset)
val lineStart = editor.document.getLineStartOffset(line)
val lineEnd = editor.document.getLineEndOffset(line)
VimPlugin.getMark().setChangeMarks(IjVimEditor(editor), TextRange(lineStart, lineEnd))
Operator().apply(editor, context, SelectionType.LINE_WISE)
}
}
private class CommentMotionVHandler : VimExtensionHandler {
override fun execute(editor: Editor, context: DataContext) {
if (!editor.caretModel.primaryCaret.hasSelection()) {

View File

@ -240,4 +240,26 @@ class CommentaryExtensionTest : JavaVimTestCase() {
""".trimIndent()
)
}
fun `test comment line with count`() {
doTest(
parseKeys("4gcc"),
"""
final Int value1 = 42;
final Int <caret>value2 = 42;
final Int value3 = 42;
final Int value4 = 42;
final Int value5 = 42;
final Int value6 = 42;
""".trimIndent(),
"""
final Int value1 = 42;
//final Int value2 = 42;
//final Int value3 = 42;
//final Int value4 = 42;
//final Int value5 = 42;
final Int value6 = 42;
""".trimIndent()
)
}
}