Skip to content

Commit

Permalink
Fix(VIM-3176): Reselecting visual selection after pasting above it se…
Browse files Browse the repository at this point in the history
…lect wrong lines
  • Loading branch information
lippfi committed Nov 23, 2023
1 parent ed1f3ce commit 8fcca05
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,63 @@

package org.jetbrains.plugins.ideavim.ex.implementation.commands

import com.intellij.idea.TestFor
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.newapi.vim
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test

class MarksCommandTest : VimTestCase() {
@Test
@TestFor(issues = ["VIM-3176"])
fun `test gv after pasting to the same line`() {
configureByText(
"""${c}I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
typeText(injector.parser.parseKeys("V3j" + "y" + "P" + "gv"))
assertState(
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
|${s}I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|${c}hard by the torrent of a mountain pass.${se}
""".trimMargin(),
)
}

@Test
@TestFor(issues = ["VIM-3176"])
fun `test gv after pasting to the same line reversed selection`() {
configureByText(
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|${c}hard by the torrent of a mountain pass.
""".trimMargin(),
)
typeText(injector.parser.parseKeys("V3k" + "y" + "P" + "gv"))
assertState(
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
|${s}${c}I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.${se}
""".trimMargin(),
)
}

// https://youtrack.jetbrains.com/issue/VIM-2223
@Test
@TestFor(issues = ["VIM-2223"])
fun `test gv after replacing a line`() {
configureByText(
"""I found it in a legendary land
Expand All @@ -35,8 +83,8 @@ class MarksCommandTest : VimTestCase() {
)
}

// https://youtrack.jetbrains.com/issue/VIM-1684
@Test
@TestFor(issues = ["VIM-1684"])
fun `test reselecting different text length`() {
configureByText(
"""
Expand All @@ -53,8 +101,8 @@ class MarksCommandTest : VimTestCase() {
)
}

// https://youtrack.jetbrains.com/issue/VIM-2491
@Test
@TestFor(issues = ["VIM-2491"])
fun `test mapping with gv`() {
configureByText("Oh, hi ${c}Andy Tom John")
typeText(commandToKeys("xnoremap p pgvy"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,13 @@ public abstract class VimMarkServiceBase : VimMarkService {

val startPosition = selectionInfo.start
var newStartPosition = selectionInfo.start
if (startPosition != null && insStart.line < startPosition.line) {
if (startPosition != null && insStart.line <= startPosition.line) {
newStartPosition = BufferPosition(startPosition.line + lines, startPosition.column, startPosition.leansForward)
}

val endPosition = selectionInfo.end
var newEndPosition = endPosition
if (endPosition != null && insStart.line < endPosition.line) {
if (endPosition != null && insStart.line <= endPosition.line) {
newEndPosition = BufferPosition(endPosition.line + lines, endPosition.column, endPosition.leansForward)
}

Expand Down

0 comments on commit 8fcca05

Please sign in to comment.