mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-03-07 12:32:52 +01:00
Handle tab character with block visual selection
This commit is contained in:
parent
7b32b75052
commit
cfcdbffa7f
src/com/maddyhome/idea/vim/group/visual
test/org/jetbrains/plugins/ideavim/action/motion
@ -208,12 +208,22 @@ private fun setVisualSelection(selectionStart: Int, selectionEnd: Int, caret: Ca
|
||||
for (aCaret in editor.caretModel.allCarets) {
|
||||
val line = aCaret.logicalPosition.line
|
||||
val lineEndOffset = EditorHelper.getLineEndOffset(editor, line, true)
|
||||
val lineStartOffset = EditorHelper.getLineStartOffset(editor, line)
|
||||
|
||||
if (lastColumn >= MotionGroup.LAST_COLUMN) {
|
||||
aCaret.vimSetSystemSelectionSilently(aCaret.selectionStart, lineEndOffset)
|
||||
}
|
||||
if (mode != CommandState.Mode.SELECT && !EditorHelper.isLineEmpty(editor, line, false) && aCaret.offset == aCaret.selectionEnd) {
|
||||
aCaret.moveToOffset(aCaret.selectionEnd - 1)
|
||||
val visualPosition = editor.offsetToVisualPosition(aCaret.selectionEnd)
|
||||
if (aCaret.offset == aCaret.selectionEnd && visualPosition != aCaret.visualPosition) {
|
||||
// Put right caret position for tab character
|
||||
aCaret.moveToVisualPosition(visualPosition)
|
||||
}
|
||||
if (mode != CommandState.Mode.SELECT
|
||||
&& !EditorHelper.isLineEmpty(editor, line, false)
|
||||
&& aCaret.offset == aCaret.selectionEnd
|
||||
&& aCaret.selectionEnd - 1 >= lineStartOffset
|
||||
&& aCaret.selectionEnd - aCaret.selectionStart != 0) {
|
||||
aCaret.moveToVisualPosition(VisualPosition(visualPosition.line, visualPosition.column - 1))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,82 @@
|
||||
@file:Suppress("RemoveCurlyBracesFromTemplate")
|
||||
|
||||
package org.jetbrains.plugins.ideavim.action.motion.select.motion
|
||||
|
||||
import com.intellij.openapi.fileTypes.PlainTextFileType
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
|
||||
/**
|
||||
* @author Alex Plate
|
||||
*/
|
||||
class SelectExtendVariousMotionsTest : VimTestCase() {
|
||||
|
||||
fun `test with tabs`() {
|
||||
val code = """
|
||||
class Scratch {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
if ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func myFunc() {
|
||||
return anything
|
||||
${c}}
|
||||
""".trimIndent()
|
||||
|
||||
myFixture.configureByText(PlainTextFileType.INSTANCE, code)
|
||||
|
||||
typeText(parseKeys("g<C-H>", "<S-UP>".repeat(2), "<S-Right>".repeat(2)))
|
||||
|
||||
myFixture.checkResult("""
|
||||
class Scratch {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
if ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
${s}fun${c}${se}c myFunc() {
|
||||
${s}${c}${se} return anything
|
||||
${s}}${c}${se}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
typeText(parseKeys("<S-UP>".repeat(7), "<S-Right>".repeat(3)))
|
||||
|
||||
myFixture.checkResult("""
|
||||
class Scratch {
|
||||
${s} pu${c}${se}blic static void main(String[] args) {
|
||||
${s} ${c}${se} try {
|
||||
${s} ${c}${se} if ()
|
||||
${s} ${c}${se} }
|
||||
${s} }${c}${se}
|
||||
${s}}${c}${se}
|
||||
|
||||
${s}func m${c}${se}yFunc() {
|
||||
${s} re${c}${se}turn anything
|
||||
${s}}${c}${se}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
typeText(parseKeys("<S-Right>".repeat(2)))
|
||||
|
||||
myFixture.checkResult("""
|
||||
class Scratch {
|
||||
${s} publ${c}${se}ic static void main(String[] args) {
|
||||
${s} ${c}${se}try {
|
||||
${s} ${c}${se} if ()
|
||||
${s} ${c}${se}}
|
||||
${s} }${c}${se}
|
||||
${s}}${c}${se}
|
||||
|
||||
${s}func myF${c}${se}unc() {
|
||||
${s} retu${c}${se}rn anything
|
||||
${s}}${c}${se}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
@file:Suppress("RemoveCurlyBracesFromTemplate")
|
||||
|
||||
package org.jetbrains.plugins.ideavim.action.motion.updown
|
||||
|
||||
import com.intellij.openapi.fileTypes.PlainTextFileType
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
|
||||
/**
|
||||
* @author Alex Plate
|
||||
*/
|
||||
class VisualVariousMotionsTest : VimTestCase() {
|
||||
|
||||
fun `test with tabs`() {
|
||||
val code = """
|
||||
class Scratch {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
if ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func myFunc() {
|
||||
return anything
|
||||
${c}}
|
||||
""".trimIndent()
|
||||
|
||||
myFixture.configureByText(PlainTextFileType.INSTANCE, code)
|
||||
|
||||
typeText(parseKeys("<C-V>", "k".repeat(2), "l".repeat(2)))
|
||||
|
||||
myFixture.checkResult("""
|
||||
class Scratch {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
if ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
${s}fu${c}n${se}c myFunc() {
|
||||
${s}${c}${se} return anything
|
||||
${s}${c}}${se}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
typeText(parseKeys("k".repeat(7), "l".repeat(3)))
|
||||
|
||||
// Carets 2-4 have 0 column as logical position, but ${se} - 1 column as visual position
|
||||
myFixture.checkResult("""
|
||||
class Scratch {
|
||||
${s} pu${c}b${se}lic static void main(String[] args) {
|
||||
${s}${c} ${se} try {
|
||||
${s}${c} ${se} if ()
|
||||
${s}${c} ${se} }
|
||||
${s} ${c}}${se}
|
||||
${s}${c}}${se}
|
||||
|
||||
${s}func m${c}y${se}Func() {
|
||||
${s} re${c}t${se}urn anything
|
||||
${s}${c}}${se}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
TestCase.assertEquals(3, myFixture.editor.caretModel.allCarets[1].visualPosition.column)
|
||||
TestCase.assertEquals(3, myFixture.editor.caretModel.allCarets[2].visualPosition.column)
|
||||
TestCase.assertEquals(3, myFixture.editor.caretModel.allCarets[3].visualPosition.column)
|
||||
|
||||
typeText(parseKeys("l".repeat(2)))
|
||||
|
||||
myFixture.checkResult("""
|
||||
class Scratch {
|
||||
${s} publ${c}i${se}c static void main(String[] args) {
|
||||
${s} ${c}t${se}ry {
|
||||
${s} ${c} ${se} if ()
|
||||
${s} ${c}}${se}
|
||||
${s} ${c}}${se}
|
||||
${s}${c}}${se}
|
||||
|
||||
${s}func myF${c}u${se}nc() {
|
||||
${s} retu${c}r${se}n anything
|
||||
${s}${c}}${se}
|
||||
""".trimIndent()
|
||||
)
|
||||
TestCase.assertEquals(7, myFixture.editor.caretModel.allCarets[2].visualPosition.column)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user