Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | helix-term/src/commands.rs | 6 | ||||
| -rw-r--r-- | helix-term/tests/test/commands.rs | 20 |
2 files changed, 26 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 52efcf22..85842523 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2271,6 +2271,12 @@ fn search_selection_detect_word_boundaries(cx: &mut Context) { fn search_selection_impl(cx: &mut Context, detect_word_boundaries: bool) { fn is_at_word_start(text: RopeSlice, index: usize) -> bool { + // This can happen when the cursor is at the last character in + // the document +1 (ge + j), in this case text.char(index) will panic as + // it will index out of bounds. See https://github.com/helix-editor/helix/issues/12609 + if index == text.len_chars() { + return false; + } let ch = text.char(index); if index == 0 { return char_is_word(ch); diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 3e2d4b52..c42d7b06 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -7,6 +7,26 @@ mod movement; mod write; #[tokio::test(flavor = "multi_thread")] +async fn after_the_final_char() -> anyhow::Result<()> { + // <https://github.com/helix-editor/helix/issues/12609> + test(( + indoc! {"\ + #[o|]#ne + two + three"}, + "gej*h", + indoc! {"\ + one + two + three#[ + |]#"}, + )) + .await?; + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread")] async fn test_selection_duplication() -> anyhow::Result<()> { // Forward test(( |