|
|
@ -302,6 +302,7 @@ impl Command {
|
|
|
|
format_selections, "Format selection",
|
|
|
|
format_selections, "Format selection",
|
|
|
|
join_selections, "Join lines inside selection",
|
|
|
|
join_selections, "Join lines inside selection",
|
|
|
|
keep_selections, "Keep selections matching regex",
|
|
|
|
keep_selections, "Keep selections matching regex",
|
|
|
|
|
|
|
|
remove_selections, "Remove selections matching regex",
|
|
|
|
keep_primary_selection, "Keep primary selection",
|
|
|
|
keep_primary_selection, "Keep primary selection",
|
|
|
|
remove_primary_selection, "Remove primary selection",
|
|
|
|
remove_primary_selection, "Remove primary selection",
|
|
|
|
completion, "Invoke completion popup",
|
|
|
|
completion, "Invoke completion popup",
|
|
|
@ -4320,12 +4321,12 @@ fn join_selections(cx: &mut Context) {
|
|
|
|
doc.append_changes_to_history(view.id);
|
|
|
|
doc.append_changes_to_history(view.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn keep_selections(cx: &mut Context) {
|
|
|
|
fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
|
|
|
|
// keep selections matching regex
|
|
|
|
// keep or remove selections matching regex
|
|
|
|
let reg = cx.register.unwrap_or('/');
|
|
|
|
let reg = cx.register.unwrap_or('/');
|
|
|
|
let prompt = ui::regex_prompt(
|
|
|
|
let prompt = ui::regex_prompt(
|
|
|
|
cx,
|
|
|
|
cx,
|
|
|
|
"keep:".into(),
|
|
|
|
if !remove { "keep:" } else { "remove:" }.into(),
|
|
|
|
Some(reg),
|
|
|
|
Some(reg),
|
|
|
|
|_input: &str| Vec::new(),
|
|
|
|
|_input: &str| Vec::new(),
|
|
|
|
move |view, doc, regex, event| {
|
|
|
|
move |view, doc, regex, event| {
|
|
|
@ -4334,7 +4335,9 @@ fn keep_selections(cx: &mut Context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(selection) = selection::keep_matches(text, doc.selection(view.id), ®ex) {
|
|
|
|
if let Some(selection) =
|
|
|
|
|
|
|
|
selection::keep_or_remove_matches(text, doc.selection(view.id), ®ex, remove)
|
|
|
|
|
|
|
|
{
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -4343,6 +4346,14 @@ fn keep_selections(cx: &mut Context) {
|
|
|
|
cx.push_layer(Box::new(prompt));
|
|
|
|
cx.push_layer(Box::new(prompt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn keep_selections(cx: &mut Context) {
|
|
|
|
|
|
|
|
keep_or_remove_selections_impl(cx, false)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn remove_selections(cx: &mut Context) {
|
|
|
|
|
|
|
|
keep_or_remove_selections_impl(cx, true)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn keep_primary_selection(cx: &mut Context) {
|
|
|
|
fn keep_primary_selection(cx: &mut Context) {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
// TODO: handle count
|
|
|
|
// TODO: handle count
|
|
|
|