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
+90
View File
@@ -3312,6 +3312,96 @@ mod test {
cx.shared_state().await.assert_eq("ˇ(\n {()} \n)");
}
#[gpui::test]
async fn test_unmatched_forward_markdown(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new_markdown_with_rust(cx).await;
cx.neovim.exec("set filetype=markdown").await;
cx.set_shared_state(indoc! {r"
```rs
impl Worktree {
pub async fn open_buffers(&self, path: &Path) -> impl Iterator<&Buffer> {
ˇ }
}
```
"})
.await;
cx.simulate_shared_keystrokes("] }").await;
cx.shared_state().await.assert_eq(indoc! {r"
```rs
impl Worktree {
pub async fn open_buffers(&self, path: &Path) -> impl Iterator<&Buffer> {
ˇ}
}
```
"});
cx.set_shared_state(indoc! {r"
```rs
impl Worktree {
pub async fn open_buffers(&self, path: &Path) -> impl Iterator<&Buffer> {
} ˇ
}
```
"})
.await;
cx.simulate_shared_keystrokes("] }").await;
cx.shared_state().await.assert_eq(indoc! {r"
```rs
impl Worktree {
pub async fn open_buffers(&self, path: &Path) -> impl Iterator<&Buffer> {
} •
ˇ}
```
"});
}
#[gpui::test]
async fn test_unmatched_backward_markdown(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new_markdown_with_rust(cx).await;
cx.neovim.exec("set filetype=markdown").await;
cx.set_shared_state(indoc! {r"
```rs
impl Worktree {
pub async fn open_buffers(&self, path: &Path) -> impl Iterator<&Buffer> {
ˇ }
}
```
"})
.await;
cx.simulate_shared_keystrokes("[ {").await;
cx.shared_state().await.assert_eq(indoc! {r"
```rs
impl Worktree {
pub async fn open_buffers(&self, path: &Path) -> impl Iterator<&Buffer> ˇ{
}
}
```
"});
cx.set_shared_state(indoc! {r"
```rs
impl Worktree {
pub async fn open_buffers(&self, path: &Path) -> impl Iterator<&Buffer> {
} ˇ
}
```
"})
.await;
cx.simulate_shared_keystrokes("[ {").await;
cx.shared_state().await.assert_eq(indoc! {r"
```rs
impl Worktree ˇ{
pub async fn open_buffers(&self, path: &Path) -> impl Iterator<&Buffer> {
} •
}
```
"});
}
#[gpui::test]
async fn test_matching_tags(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new_html(cx).await;
@@ -183,6 +183,26 @@ impl NeovimBackedTestContext {
}
}
pub async fn new_markdown_with_rust(cx: &mut gpui::TestAppContext) -> NeovimBackedTestContext {
#[cfg(feature = "neovim")]
cx.executor().allow_parking();
let thread = thread::current();
let test_name = thread
.name()
.expect("thread is not named")
.split(':')
.next_back()
.unwrap()
.to_string();
Self {
cx: VimTestContext::new_markdown_with_rust(cx).await,
neovim: NeovimConnection::new(test_name).await,
last_set_state: None,
recent_keystrokes: Default::default(),
}
}
pub async fn new_typescript(cx: &mut gpui::TestAppContext) -> NeovimBackedTestContext {
#[cfg(feature = "neovim")]
cx.executor().allow_parking();
+5
View File
@@ -41,6 +41,11 @@ impl VimTestContext {
Self::new_with_lsp(EditorLspTestContext::new_html(cx).await, true)
}
pub async fn new_markdown_with_rust(cx: &mut gpui::TestAppContext) -> VimTestContext {
Self::init(cx);
Self::new_with_lsp(EditorLspTestContext::new_markdown_with_rust(cx).await, true)
}
pub async fn new_typescript(cx: &mut gpui::TestAppContext) -> VimTestContext {
Self::init(cx);
Self::new_with_lsp(