diff --git a/src/test/java/org/jetbrains/plugins/ideavim/action/motion/text/MotionSentenceNextStartActionTest.kt b/src/test/java/org/jetbrains/plugins/ideavim/action/motion/text/MotionSentenceNextStartActionTest.kt new file mode 100644 index 000000000..16513a6f2 --- /dev/null +++ b/src/test/java/org/jetbrains/plugins/ideavim/action/motion/text/MotionSentenceNextStartActionTest.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2003-2023 The IdeaVim authors + * + * Use of this source code is governed by an MIT-style + * license that can be found in the LICENSE.txt file or at + * https://opensource.org/licenses/MIT. + */ + +package org.jetbrains.plugins.ideavim.action.motion.text + +import com.maddyhome.idea.vim.command.VimStateMachine +import org.jetbrains.plugins.ideavim.VimTestCase +import org.junit.jupiter.api.Test + +class MotionSentenceNextStartActionTest : VimTestCase() { + @Test + fun `test with two empty lines`() { + doTest( + "C<CR><S-Left><C-Right><C-O>)", + """ + Lorem ipsum dolor sit amet, + consectetur adipiscing elit + Sed in orci mauris. + Cras id tellus in ${c}ex imperdiet egestas. + """.trimIndent(), + """ + Lorem ipsum dolor sit amet, + consectetur adipiscing elit + Sed in orci mauris. + Cras id tellus in + + """.trimIndent(), + VimStateMachine.Mode.INSERT, + VimStateMachine.SubMode.NONE, + ) + } +} diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimSearchHelperBase.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimSearchHelperBase.kt index ada4a8681..db4d48923 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimSearchHelperBase.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimSearchHelperBase.kt @@ -526,7 +526,7 @@ public abstract class VimSearchHelperBase : VimSearchHelper { end?.let { findSentenceEnd(editor, chars, it - 1, max, dir, countCurrent) } } var res: Int? = null - if (end != null && (chars[end] != '\n' || !countCurrent)) { + if (end != null && end < chars.length && (chars[end] != '\n' || !countCurrent)) { res = end + 1 while (res < max) { val ch = chars[res]