diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 821018836..f3d439292 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -354,16 +354,13 @@ fn create_file_operation_prompt( ) where F: Fn(&mut Context, &PathBuf, String) -> Option> + Send + 'static, { - cx.editor.file_explorer_selected_path = Some(path.to_path_buf()); + let selected_path = path.to_path_buf(); let callback = Box::pin(async move { let call: Callback = Callback::EditorCompositor(Box::new(move |editor, compositor| { - let mut prompt = Prompt::new( - editor - .file_explorer_selected_path - .as_ref() - .map(|p| prompt(p)) - .unwrap_or_default() - .into(), + // to be able to move selected_path + let path = selected_path.clone(); + let prompt = Prompt::new( + prompt(&path).into(), None, crate::ui::completers::none, move |cx, input: &str, event: PromptEvent| { @@ -371,24 +368,14 @@ fn create_file_operation_prompt( return; }; - let path = cx.editor.file_explorer_selected_path.clone(); - - if let Some(path) = path { - match file_op(cx, &path, input.to_owned()) { - Some(Ok(msg)) => cx.editor.set_status(msg), - Some(Err(msg)) => cx.editor.set_error(msg), - None => cx.editor.clear_status(), - }; - } else { - cx.editor - .set_error("Unable to determine path of selected file") - } + match file_op(cx, &path, input.to_owned()) { + Some(Ok(msg)) => cx.editor.set_status(msg), + Some(Err(msg)) => cx.editor.set_error(msg), + None => cx.editor.clear_status(), + }; }, - ); - - if let Some(path_editing) = &editor.file_explorer_selected_path { - prompt.set_line_no_recalculate(prefill(path_editing)); - } + ) + .with_line(prefill(&selected_path), editor); compositor.push(Box::new(prompt)); })); diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 42e7bd672..9c6527c4b 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -522,7 +522,7 @@ impl Picker { self.show_preview = !self.show_preview; } - fn custom_event_handler(&mut self, event: &KeyEvent, cx: &mut Context) -> EventResult { + fn custom_key_event_handler(&mut self, event: &KeyEvent, cx: &mut Context) -> EventResult { if let (Some(callback), Some(selected)) = (self.custom_key_handlers.get(event), self.selection()) { @@ -1070,7 +1070,8 @@ impl Component for Picker, pub cursor_cache: CursorCache, - pub file_explorer_selected_path: Option, } pub type Motion = Box; @@ -1224,7 +1223,6 @@ impl Editor { handlers, mouse_down_range: None, cursor_cache: CursorCache::default(), - file_explorer_selected_path: None, } }