Skip to content

Commit

Permalink
sq
Browse files Browse the repository at this point in the history
  • Loading branch information
dead10ck committed Jun 7, 2023
1 parent 83a320c commit 3a4afeb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
17 changes: 9 additions & 8 deletions helix-core/src/auto_pairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,17 @@ pub fn handle_delete(doc: &Rope, range: &Range) -> Option<(Deletion, Range)> {

// if the range is a single grapheme cursor, we do not want to shrink the
// range, just move it, so we only subtract the size of the closing pair char
let next_anchor_delta = if range.is_single_grapheme(text) {
end_next - cursor
} else {
size_delete
let next_anchor = match (range.direction(), range.is_single_grapheme(text)) {
// single grapheme forward needs to move, but only the width of the
// character under the cursor, which is the closer
(Direction::Forward, true) => range.anchor - (end_next - cursor),
(Direction::Backward, true) => range.anchor - (cursor - end_prev),

(Direction::Forward, false) => range.anchor,
(Direction::Backward, false) => range.anchor - size_delete,
};

let next_range = match range.direction() {
Direction::Forward => Range::new(range.anchor, next_head),
Direction::Backward => Range::new(range.anchor - next_anchor_delta, next_head),
};
let next_range = Range::new(next_anchor, next_head);

log::trace!(
"auto pair delete: {:?}, range: {:?}, next_range: {:?}, text len: {}",
Expand Down
14 changes: 14 additions & 0 deletions helix-term/tests/test/auto_pairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,20 @@ async fn delete_after_word() -> anyhow::Result<()> {

#[tokio::test(flavor = "multi_thread")]
async fn insert_then_delete() -> anyhow::Result<()> {
for pair in differing_pairs() {
test((
helpers::platform_line("#[\n|]#\n"),
format!("ofoo{}<backspace>", pair.0),
helpers::platform_line("\nfoo#[\n|]#\n"),
))
.await?;
}

Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn insert_then_delete_whitespace() -> anyhow::Result<()> {
for pair in differing_pairs() {
test((
helpers::platform_line("foo#[\n|]#"),
Expand Down

0 comments on commit 3a4afeb

Please sign in to comment.