editor: Fix MoveToEnclosingBracket and unmatched forward/backward Vim motions in Markdown code blocks (#42813)

We now correctly use bracket ranges from the deepest syntax layer when
finding enclosing brackets.

Release Notes:

- Fixed an issue where `MoveToEnclosingBracket` didn’t work correctly
inside Markdown code blocks.
- Fixed an issue where unmatched forward/backward Vim motions didn’t
work correctly inside Markdown code blocks.

---------

Co-authored-by: MuskanPaliwal <muskan10112002@gmail.com>
This commit is contained in:
Smit Barmase
2025-11-15 23:57:49 +05:30
committed by GitHub
co-authored by MuskanPaliwal
parent 07cc87b288
commit 1683052e6c
10 changed files with 274 additions and 3 deletions
+9 -2
View File
@@ -823,6 +823,7 @@ pub struct BracketMatch {
pub open_range: Range<usize>,
pub close_range: Range<usize>,
pub newline_only: bool,
pub depth: usize,
}
impl Buffer {
@@ -4136,6 +4137,7 @@ impl BufferSnapshot {
while let Some(mat) = matches.peek() {
let mut open = None;
let mut close = None;
let depth = mat.depth;
let config = &configs[mat.grammar_index];
let pattern = &config.patterns[mat.pattern_index];
for capture in mat.captures {
@@ -4161,6 +4163,7 @@ impl BufferSnapshot {
open_range,
close_range,
newline_only: pattern.newline_only,
depth,
});
}
None
@@ -4320,8 +4323,12 @@ impl BufferSnapshot {
) -> impl Iterator<Item = BracketMatch> + '_ {
let range = range.start.to_offset(self)..range.end.to_offset(self);
self.bracket_ranges(range.clone()).filter(move |pair| {
pair.open_range.start <= range.start && pair.close_range.end >= range.end
let result: Vec<_> = self.bracket_ranges(range.clone()).collect();
let max_depth = result.iter().map(|mat| mat.depth).max().unwrap_or(0);
result.into_iter().filter(move |pair| {
pair.open_range.start <= range.start
&& pair.close_range.end >= range.end
&& pair.depth == max_depth
})
}