From 014c6388416bd45e4129f544c8116f523b4ff0e7 Mon Sep 17 00:00:00 2001 From: Krishan <54745129+krish-r@users.noreply.github.com> Date: Fri, 17 May 2024 00:20:01 +0530 Subject: [PATCH] fix match bracket matching (#10777) --- helix-core/src/match_brackets.rs | 4 ++-- helix-term/tests/test/commands/movement.rs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/helix-core/src/match_brackets.rs b/helix-core/src/match_brackets.rs index 0e08c4898c2d..5351b56dcae2 100644 --- a/helix-core/src/match_brackets.rs +++ b/helix-core/src/match_brackets.rs @@ -87,13 +87,13 @@ fn find_pair( (as_char(doc, &open), as_char(doc, &close)) { if PAIRS.contains(&(open, close)) { - if start_pos == pos_ { + if end_pos == pos_ { return Some(start_pos); } // We return the end char if the cursor is either on the start char // or at some arbitrary position between start and end char. - if traverse_parents || end_pos == pos_ { + if traverse_parents || start_pos == pos_ { return Some(end_pos); } } diff --git a/helix-term/tests/test/commands/movement.rs b/helix-term/tests/test/commands/movement.rs index ed6984288ec4..5868fa49433c 100644 --- a/helix-term/tests/test/commands/movement.rs +++ b/helix-term/tests/test/commands/movement.rs @@ -895,6 +895,22 @@ async fn match_bracket() -> anyhow::Result<()> { } "##}, ), + // named node with 2 or more children + ( + indoc! {r##" + use a::#[{|]# + b::{c, d, e, f, g}, + h, i, j, k, l, m, n, + }; + "##}, + "mm", + indoc! {r##" + use a::{ + b::{c, d, e, f, g}, + h, i, j, k, l, m, n, + #[}|]#; + "##}, + ), ]; let python_tests = vec![