|
|
@ -3868,7 +3868,7 @@ pub mod insert {
|
|
|
|
auto_pairs
|
|
|
|
auto_pairs
|
|
|
|
.as_ref()
|
|
|
|
.as_ref()
|
|
|
|
.and_then(|ap| {
|
|
|
|
.and_then(|ap| {
|
|
|
|
auto_pairs::hook(text, range, c, ap)
|
|
|
|
auto_pairs::hook_insert(text, range, c, ap)
|
|
|
|
.map(|(change, range)| (change, Some(range)))
|
|
|
|
.map(|(change, range)| (change, Some(range)))
|
|
|
|
.or(Some(insert_char(*range, c)))
|
|
|
|
.or(Some(insert_char(*range, c)))
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -4055,11 +4055,13 @@ pub mod insert {
|
|
|
|
let indent_width = doc.indent_width();
|
|
|
|
let indent_width = doc.indent_width();
|
|
|
|
let auto_pairs = doc.auto_pairs(cx.editor);
|
|
|
|
let auto_pairs = doc.auto_pairs(cx.editor);
|
|
|
|
|
|
|
|
|
|
|
|
let transaction =
|
|
|
|
let transaction = Transaction::delete_by_and_with_selection(
|
|
|
|
Transaction::delete_by_selection(doc.text(), doc.selection(view.id), |range| {
|
|
|
|
doc.text(),
|
|
|
|
|
|
|
|
doc.selection(view.id),
|
|
|
|
|
|
|
|
|range| {
|
|
|
|
let pos = range.cursor(text);
|
|
|
|
let pos = range.cursor(text);
|
|
|
|
if pos == 0 {
|
|
|
|
if pos == 0 {
|
|
|
|
return (pos, pos);
|
|
|
|
return ((pos, pos), None);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let line_start_pos = text.line_to_char(range.cursor_line(text));
|
|
|
|
let line_start_pos = text.line_to_char(range.cursor_line(text));
|
|
|
|
// consider to delete by indent level if all characters before `pos` are indent units.
|
|
|
|
// consider to delete by indent level if all characters before `pos` are indent units.
|
|
|
@ -4067,7 +4069,10 @@ pub mod insert {
|
|
|
|
if !fragment.is_empty() && fragment.chars().all(|ch| ch == ' ' || ch == '\t') {
|
|
|
|
if !fragment.is_empty() && fragment.chars().all(|ch| ch == ' ' || ch == '\t') {
|
|
|
|
if text.get_char(pos.saturating_sub(1)) == Some('\t') {
|
|
|
|
if text.get_char(pos.saturating_sub(1)) == Some('\t') {
|
|
|
|
// fast path, delete one char
|
|
|
|
// fast path, delete one char
|
|
|
|
(graphemes::nth_prev_grapheme_boundary(text, pos, 1), pos)
|
|
|
|
(
|
|
|
|
|
|
|
|
(graphemes::nth_prev_grapheme_boundary(text, pos, 1), pos),
|
|
|
|
|
|
|
|
None,
|
|
|
|
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let width: usize = fragment
|
|
|
|
let width: usize = fragment
|
|
|
|
.chars()
|
|
|
|
.chars()
|
|
|
@ -4094,7 +4099,7 @@ pub mod insert {
|
|
|
|
_ => break,
|
|
|
|
_ => break,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(start, pos) // delete!
|
|
|
|
((start, pos), None) // delete!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
match (
|
|
|
|
match (
|
|
|
@ -4109,19 +4114,27 @@ pub mod insert {
|
|
|
|
&& ap.get(_x).unwrap().close == _y =>
|
|
|
|
&& ap.get(_x).unwrap().close == _y =>
|
|
|
|
// delete both autopaired characters
|
|
|
|
// delete both autopaired characters
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
(
|
|
|
|
(
|
|
|
|
(
|
|
|
|
graphemes::nth_prev_grapheme_boundary(text, pos, count),
|
|
|
|
graphemes::nth_prev_grapheme_boundary(text, pos, count),
|
|
|
|
graphemes::nth_next_grapheme_boundary(text, pos, count),
|
|
|
|
graphemes::nth_next_grapheme_boundary(text, pos, count),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
None,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ =>
|
|
|
|
_ =>
|
|
|
|
// delete 1 char
|
|
|
|
// delete 1 char
|
|
|
|
{
|
|
|
|
{
|
|
|
|
(graphemes::nth_prev_grapheme_boundary(text, pos, count), pos)
|
|
|
|
(
|
|
|
|
|
|
|
|
(graphemes::nth_prev_grapheme_boundary(text, pos, count), pos),
|
|
|
|
|
|
|
|
None,
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
doc.apply(&transaction, view.id);
|
|
|
|
doc.apply(&transaction, view.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|