mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-02 00:59:07 +02:00
Convert ShiftRightHandler to kotlin, write tests for handler
This commit is contained in:
parent
bd36a6d528
commit
21b9b1d7f1
src/com/maddyhome/idea/vim/ex/handler
test/org/jetbrains/plugins/ideavim/ex
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2016 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 com.maddyhome.idea.vim.ex.handler;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler;
|
||||
import com.maddyhome.idea.vim.ex.ExCommand;
|
||||
import com.maddyhome.idea.vim.handler.CaretOrder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ShiftRightHandler extends CommandHandler {
|
||||
public ShiftRightHandler() {
|
||||
super(">", ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", ARGUMENT_OPTIONAL | WRITABLE, true, CaretOrder.DECREASING_OFFSET);
|
||||
}
|
||||
|
||||
public boolean execute(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context, @NotNull ExCommand cmd) {
|
||||
final TextRange range = cmd.getTextRange(editor, caret, context, true);
|
||||
final int[] endOffsets = range.getEndOffsets();
|
||||
final List<Integer> ends = Lists.newArrayListWithCapacity(endOffsets.length);
|
||||
for (int endOffset : endOffsets) {
|
||||
ends.add(endOffset - 1);
|
||||
}
|
||||
VimPlugin.getChange().indentRange(editor, caret, context,
|
||||
new TextRange(range.getStartOffsets(), ArrayUtil.toIntArray(ends)),
|
||||
cmd.getCommand().length(), 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
45
src/com/maddyhome/idea/vim/ex/handler/ShiftRightHandler.kt
Normal file
45
src/com/maddyhome/idea/vim/ex/handler/ShiftRightHandler.kt
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2016 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 com.maddyhome.idea.vim.ex.handler
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.commands
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.handler.CaretOrder
|
||||
|
||||
class ShiftRightHandler : CommandHandler(
|
||||
commands { +">" withOptional ">".repeat(31) },
|
||||
flags(CommandHandler.ARGUMENT_OPTIONAL, CommandHandler.WRITABLE),
|
||||
true, CaretOrder.DECREASING_OFFSET
|
||||
) {
|
||||
override fun execute(editor: Editor, caret: Caret, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val range = cmd.getTextRange(editor, caret, context, true)
|
||||
val endOffsets = range.endOffsets.map { it - 1 }.toIntArray()
|
||||
VimPlugin.getChange().indentRange(editor, caret, context,
|
||||
TextRange(range.startOffsets, endOffsets),
|
||||
cmd.command.length, 1)
|
||||
return true
|
||||
}
|
||||
}
|
@ -176,28 +176,6 @@ class MultipleCaretsTest : VimTestCase() {
|
||||
myFixture.checkResult(after)
|
||||
}
|
||||
|
||||
fun testShiftRight() {
|
||||
val before = """qw<caret>e
|
||||
| rty
|
||||
| asd
|
||||
|f<caret>gh
|
||||
| zxc
|
||||
|vb<caret>n
|
||||
""".trimMargin()
|
||||
configureByJavaText(before)
|
||||
|
||||
typeText(commandToKeys(">>"))
|
||||
|
||||
val after = """ <caret>qwe
|
||||
| rty
|
||||
| asd
|
||||
| <caret>fgh
|
||||
| zxc
|
||||
| <caret>vbn
|
||||
""".trimMargin()
|
||||
myFixture.checkResult(after)
|
||||
}
|
||||
|
||||
fun testSortRangeWholeFile() {
|
||||
val before = """qwe
|
||||
|as<caret>d
|
||||
|
@ -0,0 +1,80 @@
|
||||
package org.jetbrains.plugins.ideavim.ex.handler
|
||||
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
|
||||
/**
|
||||
* @author Alex Plate
|
||||
*/
|
||||
class ShiftRightHandlerTest : VimTestCase() {
|
||||
fun `test simple right shift`() {
|
||||
val before = """ I found it in a legendary land
|
||||
| <caret>all rocks and lavender and tufted grass,
|
||||
| where it was settled on some sodden sand
|
||||
| hard by the torrent of a mountain pass.
|
||||
""".trimMargin()
|
||||
configureByJavaText(before)
|
||||
|
||||
typeText(commandToKeys(">"))
|
||||
|
||||
val after = """ I found it in a legendary land
|
||||
| <caret>all rocks and lavender and tufted grass,
|
||||
| where it was settled on some sodden sand
|
||||
| hard by the torrent of a mountain pass.
|
||||
""".trimMargin()
|
||||
myFixture.checkResult(after)
|
||||
}
|
||||
|
||||
fun `test double right shift`() {
|
||||
val before = """ I found it in a legendary land
|
||||
| <caret>all rocks and lavender and tufted grass,
|
||||
| where it was settled on some sodden sand
|
||||
| hard by the torrent of a mountain pass.
|
||||
""".trimMargin()
|
||||
configureByJavaText(before)
|
||||
|
||||
typeText(commandToKeys(">>"))
|
||||
|
||||
val after = """ I found it in a legendary land
|
||||
| <caret>all rocks and lavender and tufted grass,
|
||||
| where it was settled on some sodden sand
|
||||
| hard by the torrent of a mountain pass.
|
||||
""".trimMargin()
|
||||
myFixture.checkResult(after)
|
||||
}
|
||||
|
||||
fun `test range right shift`() {
|
||||
val before = """ I found it in a legendary land
|
||||
| <caret>all rocks and lavender and tufted grass,
|
||||
| where it was settled on some sodden sand
|
||||
| hard by the torrent of a mountain pass.
|
||||
""".trimMargin()
|
||||
configureByJavaText(before)
|
||||
|
||||
typeText(commandToKeys("3,4>"))
|
||||
|
||||
val after = """ I found it in a legendary land
|
||||
| all rocks and lavender and tufted grass,
|
||||
| <caret>where it was settled on some sodden sand
|
||||
| hard by the torrent of a mountain pass.
|
||||
""".trimMargin()
|
||||
myFixture.checkResult(after)
|
||||
}
|
||||
|
||||
fun `test multiple carets`() {
|
||||
val before = """ I found it in a legendary land
|
||||
|<caret>all rocks and lavender and tufted grass,
|
||||
| <caret>where it was settled on some sodden sand
|
||||
| hard by the<caret> torrent of a mountain pass.
|
||||
""".trimMargin()
|
||||
configureByJavaText(before)
|
||||
|
||||
typeText(commandToKeys(">"))
|
||||
|
||||
val after = """ I found it in a legendary land
|
||||
| <caret>all rocks and lavender and tufted grass,
|
||||
| <caret>where it was settled on some sodden sand
|
||||
| <caret>hard by the torrent of a mountain pass.
|
||||
""".trimMargin()
|
||||
myFixture.checkResult(after)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user