mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-05-25 00:34:09 +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
|
@Test
|
||||||
fun `test select WORD ignores punctuation`() {
|
fun `test select WORD ignores punctuation`() {
|
||||||
doTest(
|
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
|
@Test
|
||||||
fun `test select WORD with existing right-to-left selection selects start of word`() {
|
fun `test select WORD with existing right-to-left selection selects start of word`() {
|
||||||
doTest(
|
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
|
@Test
|
||||||
fun `test repeated text object expands selection to whitespace at end of line`() {
|
fun `test repeated text object expands selection to whitespace at end of line`() {
|
||||||
doTest(
|
doTest(
|
||||||
@ -449,7 +543,7 @@ class MotionInnerBigWordActionTest : VimTestCase() {
|
|||||||
|Lorem Ipsum
|
|Lorem Ipsum
|
||||||
|
|
|
|
||||||
|Lorem ipsum dolor sit amet,
|
|Lorem ipsum dolor sit amet,
|
||||||
|consectetur ${s}adipiscing elit........${c}${se}
|
|consectetur ${s}adipiscing elit.......${c}.${se}
|
||||||
|Sed in orci mauris.
|
|Sed in orci mauris.
|
||||||
|Cras id tellus in ex imperdiet egestas.
|
|Cras id tellus in ex imperdiet egestas.
|
||||||
""".trimMargin().dotToSpace(),
|
""".trimMargin().dotToSpace(),
|
||||||
@ -576,25 +670,14 @@ class MotionInnerBigWordActionTest : VimTestCase() {
|
|||||||
""".trimMargin(),
|
""".trimMargin(),
|
||||||
"""
|
"""
|
||||||
|Lorem ${s}Ipsum
|
|Lorem ${s}Ipsum
|
||||||
|
|
|
||||||
|${c}${se}
|
|${c}${se}
|
||||||
|
|
|
||||||
|Lorem ipsum dolor sit amet,
|
|Lorem ipsum dolor sit amet,
|
||||||
""".trimMargin(),
|
""".trimMargin(),
|
||||||
Mode.VISUAL(SelectionType.CHARACTER_WISE),
|
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
|
@Test
|
||||||
fun `test repeated text object expands to whitespace on following blank line`() {
|
fun `test repeated text object expands to whitespace on following blank line`() {
|
||||||
doTest(
|
doTest(
|
||||||
@ -609,7 +692,7 @@ class MotionInnerBigWordActionTest : VimTestCase() {
|
|||||||
""".trimMargin().dotToSpace(),
|
""".trimMargin().dotToSpace(),
|
||||||
"""
|
"""
|
||||||
|Lorem ${s}Ipsum
|
|Lorem ${s}Ipsum
|
||||||
|........${c}${se}
|
|.......${c}.${se}
|
||||||
|Lorem ipsum dolor sit amet,
|
|Lorem ipsum dolor sit amet,
|
||||||
|consectetur adipiscing elit
|
|consectetur adipiscing elit
|
||||||
|Sed in orci mauris.
|
|Sed in orci mauris.
|
||||||
@ -652,8 +735,8 @@ class MotionInnerBigWordActionTest : VimTestCase() {
|
|||||||
"""
|
"""
|
||||||
|Lorem ${s}Ipsum
|
|Lorem ${s}Ipsum
|
||||||
|
|
|
|
||||||
|........
|
|.......${c}.${se}
|
||||||
|${c}${se}
|
|
|
||||||
|Lorem ipsum dolor sit amet,
|
|Lorem ipsum dolor sit amet,
|
||||||
|consectetur adipiscing elit
|
|consectetur adipiscing elit
|
||||||
|Sed in orci mauris.
|
|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
|
@Test
|
||||||
fun `test select word selects up to punctuation`() {
|
fun `test select word selects up to punctuation`() {
|
||||||
doTest(
|
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
|
@Test
|
||||||
fun `test select word with existing right-to-left selection selects start of word`() {
|
fun `test select word with existing right-to-left selection selects start of word`() {
|
||||||
doTest(
|
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
|
@Test
|
||||||
fun `test repeated text object expands selection to whitespace at end of line`() {
|
fun `test repeated text object expands selection to whitespace at end of line`() {
|
||||||
doTest(
|
doTest(
|
||||||
@ -449,7 +543,7 @@ class MotionInnerWordActionTest : VimTestCase() {
|
|||||||
|Lorem Ipsum
|
|Lorem Ipsum
|
||||||
|
|
|
|
||||||
|Lorem ipsum dolor sit amet,
|
|Lorem ipsum dolor sit amet,
|
||||||
|consectetur ${s}adipiscing elit........${c}${se}
|
|consectetur ${s}adipiscing elit.......${c}.${se}
|
||||||
|Sed in orci mauris.
|
|Sed in orci mauris.
|
||||||
|Cras id tellus in ex imperdiet egestas.
|
|Cras id tellus in ex imperdiet egestas.
|
||||||
""".trimMargin().dotToSpace(),
|
""".trimMargin().dotToSpace(),
|
||||||
@ -576,25 +670,14 @@ class MotionInnerWordActionTest : VimTestCase() {
|
|||||||
""".trimMargin(),
|
""".trimMargin(),
|
||||||
"""
|
"""
|
||||||
|Lorem ${s}Ipsum
|
|Lorem ${s}Ipsum
|
||||||
|
|
|
||||||
|${c}${se}
|
|${c}${se}
|
||||||
|
|
|
||||||
|Lorem ipsum dolor sit amet,
|
|Lorem ipsum dolor sit amet,
|
||||||
""".trimMargin(),
|
""".trimMargin(),
|
||||||
Mode.VISUAL(SelectionType.CHARACTER_WISE),
|
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
|
@Test
|
||||||
fun `test repeated text object expands to whitespace on following blank line`() {
|
fun `test repeated text object expands to whitespace on following blank line`() {
|
||||||
doTest(
|
doTest(
|
||||||
@ -609,7 +692,7 @@ class MotionInnerWordActionTest : VimTestCase() {
|
|||||||
""".trimMargin().dotToSpace(),
|
""".trimMargin().dotToSpace(),
|
||||||
"""
|
"""
|
||||||
|Lorem ${s}Ipsum
|
|Lorem ${s}Ipsum
|
||||||
|........${c}${se}
|
|.......${c}.${se}
|
||||||
|Lorem ipsum dolor sit amet,
|
|Lorem ipsum dolor sit amet,
|
||||||
|consectetur adipiscing elit
|
|consectetur adipiscing elit
|
||||||
|Sed in orci mauris.
|
|Sed in orci mauris.
|
||||||
@ -652,8 +735,8 @@ class MotionInnerWordActionTest : VimTestCase() {
|
|||||||
"""
|
"""
|
||||||
|Lorem ${s}Ipsum
|
|Lorem ${s}Ipsum
|
||||||
|
|
|
|
||||||
|........
|
|.......${c}.${se}
|
||||||
|${c}${se}
|
|
|
||||||
|Lorem ipsum dolor sit amet,
|
|Lorem ipsum dolor sit amet,
|
||||||
|consectetur adipiscing elit
|
|consectetur adipiscing elit
|
||||||
|Sed in orci mauris.
|
|Sed in orci mauris.
|
||||||
|
@ -421,9 +421,11 @@ abstract class VimSearchHelperBase : VimSearchHelper {
|
|||||||
res = pos
|
res = pos
|
||||||
}
|
}
|
||||||
found = true
|
found = true
|
||||||
}
|
} else if (newChar == '\n'
|
||||||
else if (newChar == '\n' && newChar == lastChar) {
|
&& (newChar == lastChar
|
||||||
res = if (step < 0) pos + 1 else pos
|
|| (spaceWords && charType(editor, lastChar, bigWord) === CharacterHelper.CharacterType.WHITESPACE))
|
||||||
|
) {
|
||||||
|
res = if (step < 0) pos + 1 else pos - 1
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
lastChar = newChar
|
lastChar = newChar
|
||||||
|
Loading…
Reference in New Issue
Block a user