fix: panic when pressing * after the end of the file (#12611)

* fix: panic when pressing `*` at the end of the file

chore: remove incorrect additions

* docs: add info comment

* test: add new syntax to add a selection at the final character

* test: `*` panics when after the last char

* test: move into a more appopriate module

* test: fix failing

* test: account for Windows test suite

* test: choose a different strategy for custom syntax

* test: do not modify the syntax

* style: remove newline

---------

Co-authored-by: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com>
This commit is contained in:
Nikita Revenco 2025-01-21 07:05:15 +00:00 committed by GitHub
parent e7ac2fcdec
commit ba4793fca0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 0 deletions

View file

@ -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);

View file

@ -6,6 +6,26 @@ mod insert;
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