-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Auto pair-removal #2940
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
Changes from 3 commits
55b69fd
e7e591e
005f4c6
41a8f43
9659bbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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| { | ||
|
@@ -2992,14 +2993,36 @@ 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), | ||
auto_pairs, | ||
) { | ||
(Some(_x), Some(_y), Some(ap)) | ||
if range.len() == 1 | ||
&& ap.get(_x).is_some() | ||
&& ap.get(_x).unwrap().close == _y => | ||
// delete both autopaired characters | ||
{ | ||
( | ||
graphemes::nth_prev_grapheme_boundary(text, pos, count), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
If you hit backspace 3 times, you get
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
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, | ||
) | ||
} | ||
} | ||
} | ||
}); | ||
let (view, doc) = current!(cx.editor); | ||
doc.apply(&transaction, view.id); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to use
Range::is_single_grapheme
so that it also works when the cursor is over a non-ASCII grapheme.