From 44ff7e0ec712ae289156d3422c84a48a8a6fe048 Mon Sep 17 00:00:00 2001 From: Philipp Mildenberger Date: Sun, 27 Feb 2022 16:50:34 +0100 Subject: [PATCH] Add jumplist support for the search (closes #1625) --- helix-term/src/commands.rs | 4 ++++ helix-term/src/ui/mod.rs | 22 ++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 3839cbe6a0e2d..84a30dad18598 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -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(); @@ -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, diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 94b930a01cf9d..f735c957c8544 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -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( @@ -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() {