Skip to content

Commit

Permalink
fix: preserve selection direction when searching for char pair
Browse files Browse the repository at this point in the history
`find_nth_closests_pairs_pos` checks the direction backward or forward. This helps preserve the selection direction when pressing `mim` or `mam`. This commit also adds this functionality to `find_nth_pairs_pos`, so `mi(` or `ma}` also preserves direction now.
  • Loading branch information
woojiq committed Sep 15, 2023
1 parent befcd35 commit edf9474
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion helix-core/src/surround.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ pub fn find_nth_pairs_pos(
)
};

Option::zip(open, close).ok_or(Error::PairNotFound)
match range.direction() {
Direction::Forward => Option::zip(open, close).ok_or(Error::PairNotFound),
Direction::Backward => Option::zip(close, open).ok_or(Error::PairNotFound),
}
}

fn find_nth_open_pair(
Expand Down
20 changes: 20 additions & 0 deletions helix-term/tests/test/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ async fn surround_by_character() -> anyhow::Result<()> {
))
.await?;

// Selection direction is preserved
test((
"(so [many {go#[|od]#} text] here)",
"mi{",
"(so [many {#[|good]#} text] here)",
))
.await?;
test((
"(so [many {go#[|od]#} text] here)",
"mi[",
"(so [#[|many {good} text]#] here)",
))
.await?;
test((
"(so [many {go#[od|]#} text] here)",
"mi(",
"(#[so [many {good} text] here|]#)",
))
.await?;

Ok(())
}

Expand Down

0 comments on commit edf9474

Please sign in to comment.