mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 17:36:19 +04:00
feat: add delete surrounding tag functionality
This commit is contained in:
parent
6e4d022e98
commit
2a61b113de
@ -5768,8 +5768,6 @@ fn surround_replace(cx: &mut Context) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
// we don't need to touch this
|
|
||||||
// document.set_selection(view.id, *copy_selection);
|
|
||||||
document.apply(&transaction, view.id);
|
document.apply(&transaction, view.id);
|
||||||
context.editor.mode = Mode::Normal;
|
context.editor.mode = Mode::Normal;
|
||||||
},
|
},
|
||||||
@ -5846,8 +5844,33 @@ fn surround_delete(cx: &mut Context) {
|
|||||||
let text = doc.text().slice(..);
|
let text = doc.text().slice(..);
|
||||||
let selection = doc.selection(view.id);
|
let selection = doc.selection(view.id);
|
||||||
|
|
||||||
|
if surround_ch.is_some_and(|ch| ch == 'x') {
|
||||||
|
let change_pos = match surround::get_surround_pos_tag(text, &selection, count) {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(err) => {
|
||||||
|
cx.editor.set_error(err.to_string());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let transaction = Transaction::change(
|
||||||
|
doc.text(),
|
||||||
|
change_pos.iter().flat_map(|(pos, _)| {
|
||||||
|
let opening_range = pos.0;
|
||||||
|
let closing_range = pos.1;
|
||||||
|
|
||||||
|
vec![
|
||||||
|
// add extra numbers to account for "<", ">" and "/" characters
|
||||||
|
(opening_range.from() - 1, opening_range.to() + 1, None),
|
||||||
|
(closing_range.from() - 2, closing_range.to() + 1, None),
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
doc.apply(&transaction, view.id);
|
||||||
|
exit_select_mode(cx);
|
||||||
|
} else {
|
||||||
let mut change_pos =
|
let mut change_pos =
|
||||||
match surround::get_surround_pos(doc.syntax(), text, selection, surround_ch, count) {
|
match surround::get_surround_pos(doc.syntax(), text, selection, surround_ch, count)
|
||||||
|
{
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
cx.editor.set_error(err.to_string());
|
cx.editor.set_error(err.to_string());
|
||||||
@ -5859,6 +5882,7 @@ fn surround_delete(cx: &mut Context) {
|
|||||||
Transaction::change(doc.text(), change_pos.into_iter().map(|p| (p, p + 1, None)));
|
Transaction::change(doc.text(), change_pos.into_iter().map(|p| (p, p + 1, None)));
|
||||||
doc.apply(&transaction, view.id);
|
doc.apply(&transaction, view.id);
|
||||||
exit_select_mode(cx);
|
exit_select_mode(cx);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user