mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-03-05 15:32:51 +01:00
Commands work on the last line
This commit is contained in:
parent
8c3cbc49b3
commit
c350650f9c
src/com/maddyhome/idea/vim/group
test/org/jetbrains/plugins/ideavim/action/change
@ -146,8 +146,14 @@ public class MotionGroup {
|
||||
// of the line and move the end to the end of the line.
|
||||
EnumSet<CommandFlags> flags = cmd.getFlags();
|
||||
if (flags.contains(CommandFlags.FLAG_MOT_LINEWISE)) {
|
||||
start = EditorHelper.getLineStartForOffset(editor, start);
|
||||
end = Math.min(EditorHelper.getLineEndForOffset(editor, end) + 1, EditorHelperRt.getFileSize(editor));
|
||||
if (caret.getLogicalPosition().line != EditorHelper.getLineCount(editor) - 1) {
|
||||
start = EditorHelper.getLineStartForOffset(editor, start);
|
||||
end = Math.min(EditorHelper.getLineEndForOffset(editor, end) + 1, EditorHelperRt.getFileSize(editor));
|
||||
}
|
||||
else {
|
||||
start = Math.max(EditorHelper.getLineStartForOffset(editor, start) -1 , 0);
|
||||
end = EditorHelper.getLineEndForOffset(editor, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,6 @@ package org.jetbrains.plugins.ideavim.action.change.change
|
||||
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import com.maddyhome.idea.vim.helper.VimBehaviorDiffers
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
|
||||
class ChangeLineActionTest : VimTestCase() {
|
||||
@ -32,10 +31,6 @@ class ChangeLineActionTest : VimTestCase() {
|
||||
doTest(parseKeys("S"), "", "", CommandState.Mode.INSERT, CommandState.SubMode.NONE)
|
||||
}
|
||||
|
||||
@VimBehaviorDiffers(originalVimAfter = """
|
||||
I found it in a legendary land
|
||||
$c
|
||||
""")
|
||||
fun `test on last line with S`() {
|
||||
doTest(parseKeys("S"), """
|
||||
I found it in a legendary land
|
||||
@ -43,7 +38,6 @@ class ChangeLineActionTest : VimTestCase() {
|
||||
""".trimIndent(), """
|
||||
I found it in a legendary land
|
||||
$c
|
||||
|
||||
""".trimIndent(), CommandState.Mode.INSERT, CommandState.SubMode.NONE)
|
||||
}
|
||||
|
||||
@ -59,10 +53,6 @@ class ChangeLineActionTest : VimTestCase() {
|
||||
""".trimIndent(), CommandState.Mode.INSERT, CommandState.SubMode.NONE)
|
||||
}
|
||||
|
||||
@VimBehaviorDiffers(originalVimAfter = """
|
||||
I found it in a legendary land
|
||||
$c
|
||||
""")
|
||||
fun `test on very last line with new line with S`() {
|
||||
doTest(parseKeys("S"), """
|
||||
I found it in a legendary land
|
||||
@ -70,7 +60,6 @@ class ChangeLineActionTest : VimTestCase() {
|
||||
""".trimIndent(), """
|
||||
I found it in a legendary land
|
||||
$c
|
||||
|
||||
""".trimIndent(), CommandState.Mode.INSERT, CommandState.SubMode.NONE)
|
||||
}
|
||||
|
||||
@ -95,4 +84,16 @@ class ChangeLineActionTest : VimTestCase() {
|
||||
|
||||
""".trimIndent(), CommandState.Mode.INSERT, CommandState.SubMode.NONE)
|
||||
}
|
||||
|
||||
fun `test on last line`() {
|
||||
doTest(parseKeys("cc"), """
|
||||
I found it in a legendary land
|
||||
all rocks and lavender and tufted grass,
|
||||
$c
|
||||
""".trimIndent(), """
|
||||
I found it in a legendary land
|
||||
all rocks and lavender and tufted grass,
|
||||
$c
|
||||
""".trimIndent(), CommandState.Mode.INSERT, CommandState.SubMode.NONE)
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
package org.jetbrains.plugins.ideavim.action.change.delete
|
||||
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import com.maddyhome.idea.vim.helper.VimBehaviorDiffers
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
@ -40,8 +41,7 @@ class DeleteMotionActionTest : VimTestCase() {
|
||||
""".trimIndent())
|
||||
myFixture.checkResult("""
|
||||
def xxx():
|
||||
expression on${c}e
|
||||
|
||||
${c} expression one
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ class DeleteMotionActionTest : VimTestCase() {
|
||||
expression${c} two
|
||||
""".trimIndent())
|
||||
val savedText = VimPlugin.getRegister().lastRegister?.text ?: ""
|
||||
assertEquals(" expression two", savedText)
|
||||
assertEquals("\n expression two", savedText)
|
||||
}
|
||||
|
||||
fun `test delete line action multicaret`() {
|
||||
@ -122,4 +122,23 @@ class DeleteMotionActionTest : VimTestCase() {
|
||||
typeTextInFile(parseKeys("dd"), file)
|
||||
myFixture.checkResult(newFile)
|
||||
}
|
||||
|
||||
fun `test delete on last line`() {
|
||||
doTest(parseKeys("dd"),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I found it in a legendary land
|
||||
all rocks and lavender and tufted grass,
|
||||
$c
|
||||
""".trimIndent(),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I found it in a legendary land
|
||||
${c}all rocks and lavender and tufted grass,
|
||||
""".trimIndent(),
|
||||
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user