Skip to content

Commit

Permalink
fix(core): match inside closest pair inconsitency
Browse files Browse the repository at this point in the history
For example (rust):
`fn func() {func("string");}`
When the cursor was on the opening quote and you pressed "mim", new
selection was inside quotes, but it must be inside parentheses (around
the quotes). Previously, this only worked for closed pairs.
  • Loading branch information
woojiq committed Apr 27, 2024
1 parent 109f53f commit 2810946
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion helix-core/src/surround.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn find_nth_closest_pairs_ts(
}

// In case found brackets are partially inside current selection.
if range.from() < opening || closing < range.to() - 1 {
if range.from() <= opening || closing < range.to() - 1 {
closing = next_grapheme_boundary(text, closing);
} else {
skip -= 1;
Expand Down
26 changes: 26 additions & 0 deletions helix-term/tests/test/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,32 @@ async fn match_around_closest_ts() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn match_inside_closest_ts() -> anyhow::Result<()> {
// Match inside must not match inside the pair we are currently on.
test_with_config(
AppBuilder::new().with_file("foo.rs", None),
(
r#"fn main() {func(#[|"]#string");}"#,
"mim",
r#"fn main() {func(#[|"string"]#);}"#,
),
)
.await?;

test_with_config(
AppBuilder::new().with_file("foo.rs", None),
(
r#"fn main() {func("string#["|]#);}"#,
"mim",
r#"fn main() {func(#["string"|]#);}"#,
),
)
.await?;

Ok(())
}

/// Ensure the very initial cursor in an opened file is the width of
/// the first grapheme
#[tokio::test(flavor = "multi_thread")]
Expand Down

0 comments on commit 2810946

Please sign in to comment.