Skip to content

Commit

Permalink
Add jumplist support for the search (closes #1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp-M committed Feb 27, 2022
1 parent 39f7ba3 commit 44ff7e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
4 changes: 4 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,9 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir
let scrolloff = cx.editor.config.scrolloff;
let (view, doc) = current!(cx.editor);
let registers = &cx.editor.registers;
let doc_id = view.doc;
let snapshot = doc.selection(view.id);

if let Some(query) = registers.read('/') {
let query = query.last().unwrap();
let contents = doc.text().slice(..).to_string();
Expand All @@ -1643,6 +1646,7 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir
.case_insensitive(case_insensitive)
.build()
{
view.jumps.push((doc_id, snapshot.clone()));
search_impl(
doc,
view,
Expand Down
22 changes: 10 additions & 12 deletions helix-term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub fn regex_prompt(
fun: impl Fn(&mut View, &mut Document, Regex, PromptEvent) + 'static,
) -> Prompt {
let (view, doc) = current!(cx.editor);
let view_id = view.id;
let snapshot = doc.selection(view_id).clone();
let doc_id = view.doc;
let snapshot = doc.selection(view.id).clone();
let offset_snapshot = view.offset;

let mut prompt = Prompt::new(
Expand All @@ -49,17 +49,15 @@ pub fn regex_prompt(
doc.set_selection(view.id, snapshot.clone());
view.offset = offset_snapshot;
}
PromptEvent::Validate => {
// TODO: push_jump to store selection just before jump

match Regex::new(input) {
Ok(regex) => {
let (view, doc) = current!(cx.editor);
fun(view, doc, regex, event);
}
Err(_err) => (), // TODO: mark command line as error
PromptEvent::Validate => match Regex::new(input) {
Ok(regex) => {
let (view, doc) = current!(cx.editor);
view.jumps.push((doc_id, snapshot.clone()));
fun(view, doc, regex, event);
}
}
Err(_err) => (), // TODO: mark command line as error
},

PromptEvent::Update => {
// skip empty input, TODO: trigger default
if input.is_empty() {
Expand Down

0 comments on commit 44ff7e0

Please sign in to comment.