|
|
@ -1520,7 +1520,8 @@ fn select_regex(cx: &mut Context) {
|
|
|
|
"select:".into(),
|
|
|
|
"select:".into(),
|
|
|
|
Some(reg),
|
|
|
|
Some(reg),
|
|
|
|
ui::completers::none,
|
|
|
|
ui::completers::none,
|
|
|
|
move |view, doc, regex, event| {
|
|
|
|
move |editor, regex, event| {
|
|
|
|
|
|
|
|
let (view, doc) = current!(editor);
|
|
|
|
if !matches!(event, PromptEvent::Update | PromptEvent::Validate) {
|
|
|
|
if !matches!(event, PromptEvent::Update | PromptEvent::Validate) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1541,7 +1542,8 @@ fn split_selection(cx: &mut Context) {
|
|
|
|
"split:".into(),
|
|
|
|
"split:".into(),
|
|
|
|
Some(reg),
|
|
|
|
Some(reg),
|
|
|
|
ui::completers::none,
|
|
|
|
ui::completers::none,
|
|
|
|
move |view, doc, regex, event| {
|
|
|
|
move |editor, regex, event| {
|
|
|
|
|
|
|
|
let (view, doc) = current!(editor);
|
|
|
|
if !matches!(event, PromptEvent::Update | PromptEvent::Validate) {
|
|
|
|
if !matches!(event, PromptEvent::Update | PromptEvent::Validate) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1563,10 +1565,8 @@ fn split_selection_on_newline(cx: &mut Context) {
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
|
|
|
|
fn search_impl(
|
|
|
|
fn search_impl(
|
|
|
|
doc: &mut Document,
|
|
|
|
editor: &mut Editor,
|
|
|
|
view: &mut View,
|
|
|
|
|
|
|
|
contents: &str,
|
|
|
|
contents: &str,
|
|
|
|
regex: &Regex,
|
|
|
|
regex: &Regex,
|
|
|
|
movement: Movement,
|
|
|
|
movement: Movement,
|
|
|
@ -1574,6 +1574,7 @@ fn search_impl(
|
|
|
|
scrolloff: usize,
|
|
|
|
scrolloff: usize,
|
|
|
|
wrap_around: bool,
|
|
|
|
wrap_around: bool,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
let (view, doc) = current!(editor);
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
let selection = doc.selection(view.id);
|
|
|
|
let selection = doc.selection(view.id);
|
|
|
|
|
|
|
|
|
|
|
@ -1603,17 +1604,25 @@ fn search_impl(
|
|
|
|
Direction::Backward => regex.find_iter(&contents[..start]).last(),
|
|
|
|
Direction::Backward => regex.find_iter(&contents[..start]).last(),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if wrap_around && mat.is_none() {
|
|
|
|
if mat.is_none() {
|
|
|
|
|
|
|
|
if wrap_around {
|
|
|
|
mat = match direction {
|
|
|
|
mat = match direction {
|
|
|
|
Direction::Forward => regex.find(contents),
|
|
|
|
Direction::Forward => regex.find(contents),
|
|
|
|
Direction::Backward => {
|
|
|
|
Direction::Backward => {
|
|
|
|
offset = start;
|
|
|
|
offset = start;
|
|
|
|
regex.find_iter(&contents[start..]).last()
|
|
|
|
regex.find_iter(&contents[start..]).last()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
editor.set_status("Wrapped around document");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
editor.set_error("No more matches");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO: message on wraparound
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let (view, doc) = current!(editor);
|
|
|
|
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
|
|
|
|
let selection = doc.selection(view.id);
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(mat) = mat {
|
|
|
|
if let Some(mat) = mat {
|
|
|
|
let start = text.byte_to_char(mat.start() + offset);
|
|
|
|
let start = text.byte_to_char(mat.start() + offset);
|
|
|
|
let end = text.byte_to_char(mat.end() + offset);
|
|
|
|
let end = text.byte_to_char(mat.end() + offset);
|
|
|
@ -1689,13 +1698,12 @@ fn searcher(cx: &mut Context, direction: Direction) {
|
|
|
|
.map(|comp| (0.., std::borrow::Cow::Owned(comp.clone())))
|
|
|
|
.map(|comp| (0.., std::borrow::Cow::Owned(comp.clone())))
|
|
|
|
.collect()
|
|
|
|
.collect()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
move |view, doc, regex, event| {
|
|
|
|
move |editor, regex, event| {
|
|
|
|
if !matches!(event, PromptEvent::Update | PromptEvent::Validate) {
|
|
|
|
if !matches!(event, PromptEvent::Update | PromptEvent::Validate) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
search_impl(
|
|
|
|
search_impl(
|
|
|
|
doc,
|
|
|
|
editor,
|
|
|
|
view,
|
|
|
|
|
|
|
|
&contents,
|
|
|
|
&contents,
|
|
|
|
®ex,
|
|
|
|
®ex,
|
|
|
|
Movement::Move,
|
|
|
|
Movement::Move,
|
|
|
@ -1711,7 +1719,7 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let config = cx.editor.config();
|
|
|
|
let config = cx.editor.config();
|
|
|
|
let scrolloff = config.scrolloff;
|
|
|
|
let scrolloff = config.scrolloff;
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (_, doc) = current!(cx.editor);
|
|
|
|
let registers = &cx.editor.registers;
|
|
|
|
let registers = &cx.editor.registers;
|
|
|
|
if let Some(query) = registers.read('/').and_then(|query| query.last()) {
|
|
|
|
if let Some(query) = registers.read('/').and_then(|query| query.last()) {
|
|
|
|
let contents = doc.text().slice(..).to_string();
|
|
|
|
let contents = doc.text().slice(..).to_string();
|
|
|
@ -1729,8 +1737,7 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for _ in 0..count {
|
|
|
|
for _ in 0..count {
|
|
|
|
search_impl(
|
|
|
|
search_impl(
|
|
|
|
doc,
|
|
|
|
cx.editor,
|
|
|
|
view,
|
|
|
|
|
|
|
|
&contents,
|
|
|
|
&contents,
|
|
|
|
®ex,
|
|
|
|
®ex,
|
|
|
|
movement,
|
|
|
|
movement,
|
|
|
@ -1834,7 +1841,7 @@ fn global_search(cx: &mut Context) {
|
|
|
|
.map(|comp| (0.., std::borrow::Cow::Owned(comp.clone())))
|
|
|
|
.map(|comp| (0.., std::borrow::Cow::Owned(comp.clone())))
|
|
|
|
.collect()
|
|
|
|
.collect()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
move |_view, _doc, regex, event| {
|
|
|
|
move |_editor, regex, event| {
|
|
|
|
if event != PromptEvent::Validate {
|
|
|
|
if event != PromptEvent::Validate {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -3773,7 +3780,8 @@ fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
|
|
|
|
if remove { "remove:" } else { "keep:" }.into(),
|
|
|
|
if remove { "remove:" } else { "keep:" }.into(),
|
|
|
|
Some(reg),
|
|
|
|
Some(reg),
|
|
|
|
ui::completers::none,
|
|
|
|
ui::completers::none,
|
|
|
|
move |view, doc, regex, event| {
|
|
|
|
move |editor, regex, event| {
|
|
|
|
|
|
|
|
let (view, doc) = current!(editor);
|
|
|
|
if !matches!(event, PromptEvent::Update | PromptEvent::Validate) {
|
|
|
|
if !matches!(event, PromptEvent::Update | PromptEvent::Validate) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|