1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-05-29 01:34:10 +02:00

Fix out of bounds exception

This commit is contained in:
Alex Plate 2023-06-02 09:53:04 +03:00
parent 30069564a7
commit 51c464f8d2
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
2 changed files with 38 additions and 1 deletions
src/test/java/org/jetbrains/plugins/ideavim/action/motion/text
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api

View File

@ -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,
)
}
}

View File

@ -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]