mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-05-06 03:34:03 +02:00
Select trailing whitespace with viw
Inner word/WORD motions will select trailing whitespace at the end of a line without wrapping
This commit is contained in:
parent
d9e575d4a2
commit
18b4b76ebf
src/test/java/org/jetbrains/plugins/ideavim/action/motion/object
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api
@ -124,6 +124,54 @@ class MotionInnerBigWordActionTest : VimTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test select WORD from whitespace at end of line with multiple lines`() {
|
||||
doTest(
|
||||
"viW",
|
||||
"""
|
||||
|Lorem Ipsum....${c}....
|
||||
|
|
||||
|Lorem ipsum dolor sit amet
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
"""
|
||||
|Lorem Ipsum${s}.......${c}.${se}
|
||||
|
|
||||
|Lorem ipsum dolor sit amet
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
Mode.VISUAL(SelectionType.CHARACTER_WISE),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test select WORD from whitespace at end of line with multiple lines 2`() {
|
||||
doTest(
|
||||
"viW",
|
||||
"""
|
||||
|Lorem Ipsum
|
||||
|
|
||||
|Lorem ipsum dolor sit amet....${c}....
|
||||
|....consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
"""
|
||||
|Lorem Ipsum
|
||||
|
|
||||
|Lorem ipsum dolor sit amet${s}.......${c}.${se}
|
||||
|....consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
Mode.VISUAL(SelectionType.CHARACTER_WISE),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test select WORD ignores punctuation`() {
|
||||
doTest(
|
||||
@ -154,6 +202,64 @@ class MotionInnerBigWordActionTest : VimTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test select WORD with existing left-to-right selection in whitespace selects trailing whitespace at end of file`() {
|
||||
doTest(
|
||||
listOf("v", "l", "iW"),
|
||||
"Lorem ipsum dolor sit amet ${c} ",
|
||||
"Lorem ipsum dolor sit amet ${s} ${c} ${se}",
|
||||
Mode.VISUAL(SelectionType.CHARACTER_WISE),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test select WORD from whitespace at end of line with multiple lines and existing left-to-right selection`() {
|
||||
doTest(
|
||||
listOf("v", "h", "iW"),
|
||||
"""
|
||||
|Lorem Ipsum...${c}.....
|
||||
|
|
||||
|Lorem ipsum dolor sit amet
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
"""
|
||||
|Lorem Ipsum${s}${c}....${se}....
|
||||
|
|
||||
|Lorem ipsum dolor sit amet
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
Mode.VISUAL(SelectionType.CHARACTER_WISE),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test select WORD from whitespace at end of line with multiple lines and existing left-to-right selection 2`() {
|
||||
doTest(
|
||||
listOf("v", "h", "iW"),
|
||||
"""
|
||||
|Lorem Ipsum
|
||||
|
|
||||
|Lorem ipsum dolor sit amet...${c}.....
|
||||
| consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
"""
|
||||
|Lorem Ipsum
|
||||
|
|
||||
|Lorem ipsum dolor sit amet${s}${c}....${se}....
|
||||
| consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
Mode.VISUAL(SelectionType.CHARACTER_WISE),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test select WORD with existing right-to-left selection selects start of word`() {
|
||||
doTest(
|
||||
@ -421,18 +527,6 @@ class MotionInnerBigWordActionTest : VimTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: Fix this bug
|
||||
@VimBehaviorDiffers(originalVimAfter =
|
||||
"""
|
||||
|Lorem Ipsum
|
||||
|
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur ${s}adipiscing elit.......${c}.${se}
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""",
|
||||
description = "Caret placement is incorrect, but the selection is correct - it should not select the final newline char"
|
||||
)
|
||||
@Test
|
||||
fun `test repeated text object expands selection to whitespace at end of line`() {
|
||||
doTest(
|
||||
@ -449,7 +543,7 @@ class MotionInnerBigWordActionTest : VimTestCase() {
|
||||
|Lorem Ipsum
|
||||
|
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur ${s}adipiscing elit........${c}${se}
|
||||
|consectetur ${s}adipiscing elit.......${c}.${se}
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
@ -576,25 +670,14 @@ class MotionInnerBigWordActionTest : VimTestCase() {
|
||||
""".trimMargin(),
|
||||
"""
|
||||
|Lorem ${s}Ipsum
|
||||
|
|
||||
|${c}${se}
|
||||
|
|
||||
|Lorem ipsum dolor sit amet,
|
||||
""".trimMargin(),
|
||||
Mode.VISUAL(SelectionType.CHARACTER_WISE),
|
||||
)
|
||||
}
|
||||
|
||||
@VimBehaviorDiffers(originalVimAfter =
|
||||
"""
|
||||
|Lorem ${s}Ipsum
|
||||
|.......${c}.${se}
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""",
|
||||
description = "Caret placement is incorrect, but selection is correct. It should not select trailing new line char"
|
||||
)
|
||||
@Test
|
||||
fun `test repeated text object expands to whitespace on following blank line`() {
|
||||
doTest(
|
||||
@ -609,7 +692,7 @@ class MotionInnerBigWordActionTest : VimTestCase() {
|
||||
""".trimMargin().dotToSpace(),
|
||||
"""
|
||||
|Lorem ${s}Ipsum
|
||||
|........${c}${se}
|
||||
|.......${c}.${se}
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
@ -652,8 +735,8 @@ class MotionInnerBigWordActionTest : VimTestCase() {
|
||||
"""
|
||||
|Lorem ${s}Ipsum
|
||||
|
|
||||
|........
|
||||
|${c}${se}
|
||||
|.......${c}.${se}
|
||||
|
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|
@ -124,6 +124,54 @@ class MotionInnerWordActionTest : VimTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test select word from whitespace at end of line with multiple lines`() {
|
||||
doTest(
|
||||
"viw",
|
||||
"""
|
||||
|Lorem Ipsum....${c}....
|
||||
|
|
||||
|Lorem ipsum dolor sit amet
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
"""
|
||||
|Lorem Ipsum${s}.......${c}.${se}
|
||||
|
|
||||
|Lorem ipsum dolor sit amet
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
Mode.VISUAL(SelectionType.CHARACTER_WISE),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test select word from whitespace at end of line with multiple lines 2`() {
|
||||
doTest(
|
||||
"viw",
|
||||
"""
|
||||
|Lorem Ipsum
|
||||
|
|
||||
|Lorem ipsum dolor sit amet....${c}....
|
||||
|....consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
"""
|
||||
|Lorem Ipsum
|
||||
|
|
||||
|Lorem ipsum dolor sit amet${s}.......${c}.${se}
|
||||
|....consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
Mode.VISUAL(SelectionType.CHARACTER_WISE),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test select word selects up to punctuation`() {
|
||||
doTest(
|
||||
@ -154,6 +202,64 @@ class MotionInnerWordActionTest : VimTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test select word with existing left-to-right selection in whitespace selects trailing whitespace at end of file`() {
|
||||
doTest(
|
||||
listOf("v", "l", "iw"),
|
||||
"Lorem ipsum dolor sit amet ${c} ",
|
||||
"Lorem ipsum dolor sit amet ${s} ${c} ${se}",
|
||||
Mode.VISUAL(SelectionType.CHARACTER_WISE),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test select word from whitespace at end of line with multiple lines and existing left-to-right selection`() {
|
||||
doTest(
|
||||
listOf("v", "h", "iw"),
|
||||
"""
|
||||
|Lorem Ipsum...${c}.....
|
||||
|
|
||||
|Lorem ipsum dolor sit amet
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
"""
|
||||
|Lorem Ipsum${s}${c}....${se}....
|
||||
|
|
||||
|Lorem ipsum dolor sit amet
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
Mode.VISUAL(SelectionType.CHARACTER_WISE),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test select word from whitespace at end of line with multiple lines and existing left-to-right selection 2`() {
|
||||
doTest(
|
||||
listOf("v", "h", "iw"),
|
||||
"""
|
||||
|Lorem Ipsum
|
||||
|
|
||||
|Lorem ipsum dolor sit amet...${c}.....
|
||||
| consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
"""
|
||||
|Lorem Ipsum
|
||||
|
|
||||
|Lorem ipsum dolor sit amet${s}${c}....${se}....
|
||||
| consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
Mode.VISUAL(SelectionType.CHARACTER_WISE),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test select word with existing right-to-left selection selects start of word`() {
|
||||
doTest(
|
||||
@ -421,18 +527,6 @@ class MotionInnerWordActionTest : VimTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: Fix this bug
|
||||
@VimBehaviorDiffers(originalVimAfter =
|
||||
"""
|
||||
|Lorem Ipsum
|
||||
|
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur ${s}adipiscing elit.......${c}.${se}
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""",
|
||||
description = "Caret placement is incorrect, but the selection is correct - it should not select the final newline char"
|
||||
)
|
||||
@Test
|
||||
fun `test repeated text object expands selection to whitespace at end of line`() {
|
||||
doTest(
|
||||
@ -449,7 +543,7 @@ class MotionInnerWordActionTest : VimTestCase() {
|
||||
|Lorem Ipsum
|
||||
|
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur ${s}adipiscing elit........${c}${se}
|
||||
|consectetur ${s}adipiscing elit.......${c}.${se}
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin().dotToSpace(),
|
||||
@ -576,25 +670,14 @@ class MotionInnerWordActionTest : VimTestCase() {
|
||||
""".trimMargin(),
|
||||
"""
|
||||
|Lorem ${s}Ipsum
|
||||
|
|
||||
|${c}${se}
|
||||
|
|
||||
|Lorem ipsum dolor sit amet,
|
||||
""".trimMargin(),
|
||||
Mode.VISUAL(SelectionType.CHARACTER_WISE),
|
||||
)
|
||||
}
|
||||
|
||||
@VimBehaviorDiffers(originalVimAfter =
|
||||
"""
|
||||
|Lorem ${s}Ipsum
|
||||
|.......${c}.${se}
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""",
|
||||
description = "Caret placement is incorrect, but selection is correct. It should not select trailing new line char"
|
||||
)
|
||||
@Test
|
||||
fun `test repeated text object expands to whitespace on following blank line`() {
|
||||
doTest(
|
||||
@ -609,7 +692,7 @@ class MotionInnerWordActionTest : VimTestCase() {
|
||||
""".trimMargin().dotToSpace(),
|
||||
"""
|
||||
|Lorem ${s}Ipsum
|
||||
|........${c}${se}
|
||||
|.......${c}.${se}
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
@ -652,8 +735,8 @@ class MotionInnerWordActionTest : VimTestCase() {
|
||||
"""
|
||||
|Lorem ${s}Ipsum
|
||||
|
|
||||
|........
|
||||
|${c}${se}
|
||||
|.......${c}.${se}
|
||||
|
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|
@ -421,9 +421,11 @@ abstract class VimSearchHelperBase : VimSearchHelper {
|
||||
res = pos
|
||||
}
|
||||
found = true
|
||||
}
|
||||
else if (newChar == '\n' && newChar == lastChar) {
|
||||
res = if (step < 0) pos + 1 else pos
|
||||
} else if (newChar == '\n'
|
||||
&& (newChar == lastChar
|
||||
|| (spaceWords && charType(editor, lastChar, bigWord) === CharacterHelper.CharacterType.WHITESPACE))
|
||||
) {
|
||||
res = if (step < 0) pos + 1 else pos - 1
|
||||
found = true
|
||||
}
|
||||
lastChar = newChar
|
||||
|
Loading…
Reference in New Issue
Block a user