Skip to content

Commit

Permalink
autopairs removal: use doc autopairs
Browse files Browse the repository at this point in the history
  • Loading branch information
Houkime committed Jul 2, 2022
1 parent 55b69fd commit e7e591e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2937,10 +2937,11 @@ pub mod insert {

pub fn delete_char_backward(cx: &mut Context) {
let count = cx.count();
let (view, doc) = current!(cx.editor);
let (view, doc) = current_ref!(cx.editor);
let text = doc.text().slice(..);
let indent_unit = doc.indent_unit();
let tab_size = doc.tab_width();
let auto_pairs = doc.auto_pairs(cx.editor);

let transaction =
Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| {
Expand Down Expand Up @@ -2992,9 +2993,14 @@ pub mod insert {
(start, pos, None) // delete!
}
} else {
match (text.get_char(pos.saturating_sub(1)), text.get_char(pos)) {
(Some(_x), Some(_y)) if auto_pairs::DEFAULT_PAIRS.contains(&(_x, _y)) =>
// delete both
match (
text.get_char(pos.saturating_sub(1)),
text.get_char(pos),
auto_pairs,
) {
(Some(_x), Some(_y), Some(ap))
if ap.get(_x).is_some() && (ap.get(_x).unwrap().close == _y) =>
// delete both autopaired characters
{
(
graphemes::nth_prev_grapheme_boundary(text, pos, count),
Expand All @@ -3014,6 +3020,7 @@ pub mod insert {
}
}
});
let (view, doc) = current!(cx.editor);
doc.apply(&transaction, view.id);
}

Expand Down

0 comments on commit e7e591e

Please sign in to comment.