Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto pair-removal #2940

Merged
merged 5 commits into from
Jul 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2992,12 +2992,26 @@ pub mod insert {
(start, pos, None) // delete!
}
} else {
// delete char
(
graphemes::nth_prev_grapheme_boundary(text, pos, count),
pos,
None,
)
match (text.get_char(pos.saturating_sub(1)), text.get_char(pos)) {
(Some(_x), Some(_y)) if auto_pairs::DEFAULT_PAIRS.contains(&(_x, _y)) =>
Houkime marked this conversation as resolved.
Show resolved Hide resolved
// delete both
Houkime marked this conversation as resolved.
Show resolved Hide resolved
{
(
graphemes::nth_prev_grapheme_boundary(text, pos, count),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might get a bit tricky with the count. If we just delete n chars in both directions, this will be wrong in some cases. e.g. presently with this case:

hello, "["], goodbye("")

If you hit backspace 3 times, you get

hello[,] goodbye("")

like you'd expect. But if you use the command with a count, e.g. if you bound backspace to this in normal mode and then hit 3<backspace>, you end up with:

hello[g]oodbye("")

Though, I don't know how many people bind this in normal mode and use the count with it, so I don't know if I'd consider this a blocker. It might be tricky to get the logic right.

graphemes::nth_next_grapheme_boundary(text, pos, count),
None,
)
}
_ =>
// delete 1 char
{
(
graphemes::nth_prev_grapheme_boundary(text, pos, count),
pos,
None,
)
}
}
}
});
doc.apply(&transaction, view.id);
Expand Down