From 97f310a1eb19b6e0a4a2018124e8ecbbbf5917bf Mon Sep 17 00:00:00 2001 From: Philipp Mildenberger Date: Sun, 23 Jul 2023 15:46:56 +0200 Subject: [PATCH] reset idle timeout when pushing a new compositor layer Co-authored-by: Pascal Kuthe --- helix-term/src/application.rs | 4 ++-- helix-term/src/commands.rs | 14 +++++++------- helix-term/src/commands/dap.rs | 14 +++++++------- helix-term/src/commands/lsp.rs | 18 +++++++++--------- helix-term/src/commands/typed.rs | 12 ++++++------ helix-term/src/compositor.rs | 12 +++++++++--- helix-term/src/ui/mod.rs | 8 ++++++-- 7 files changed, 46 insertions(+), 36 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index dc46119891224..7333318f714df 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -157,7 +157,7 @@ impl Application { &config.keys })); let editor_view = Box::new(ui::EditorView::new(Keymaps::new(keys))); - compositor.push(editor_view); + compositor.push(editor_view, &mut editor); if args.load_tutor { let path = helix_loader::runtime_file(Path::new("tutor")); @@ -170,7 +170,7 @@ impl Application { helix_loader::set_current_working_dir(first.clone())?; editor.new_file(Action::VerticalSplit); let picker = ui::file_picker(".".into(), &config.load().editor); - compositor.push(Box::new(overlaid(picker))); + compositor.push(Box::new(overlaid(picker)), &mut editor); } else { let nr_of_files = args.files.len(); for (i, (file, pos)) in args.files.into_iter().enumerate() { diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 58c172968bb69..379c1dae55cc7 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -93,15 +93,15 @@ pub struct Context<'a> { impl<'a> Context<'a> { /// Push a new component onto the compositor. pub fn push_layer(&mut self, component: Box) { - self.callback = Some(Box::new(|compositor: &mut Compositor, _| { - compositor.push(component) + self.callback = Some(Box::new(|compositor: &mut Compositor, cx| { + compositor.push(component, cx.editor) })); } /// Call `replace_or_push` on the Compositor pub fn replace_or_push_layer(&mut self, id: &'static str, component: T) { - self.callback = Some(Box::new(move |compositor: &mut Compositor, _| { - compositor.replace_or_push(id, component); + self.callback = Some(Box::new(move |compositor: &mut Compositor, cx| { + compositor.replace_or_push(id, component, cx.editor); })); } @@ -2214,7 +2214,7 @@ fn global_search(cx: &mut Context) { }).with_preview(|_editor, FileResult { path, line_num }| { Some((path.clone().into(), Some((*line_num, *line_num)))) }); - compositor.push(Box::new(overlaid(picker))); + compositor.push(Box::new(overlaid(picker)), editor); }, )); Ok(call) @@ -2810,7 +2810,7 @@ pub fn command_palette(cx: &mut Context) { } } }); - compositor.push(Box::new(overlaid(picker))); + compositor.push(Box::new(overlaid(picker)), cx.editor); }, )); } @@ -2819,7 +2819,7 @@ fn last_picker(cx: &mut Context) { // TODO: last picker does not seem to work well with buffer_picker cx.callback = Some(Box::new(|compositor, cx| { if let Some(picker) = compositor.last_picker.take() { - compositor.push(picker); + compositor.push(picker, cx.editor); } else { cx.editor.set_error("no last picker") } diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index e26dc08dcf01b..eaeb63fe7463a 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -86,7 +86,7 @@ fn thread_picker( )); Some((path.into(), pos)) }); - compositor.push(Box::new(picker)); + compositor.push(Box::new(picker), editor); }, ); } @@ -276,9 +276,9 @@ pub fn dap_launch(cx: &mut Context) { let name = template.name.clone(); let callback = Box::pin(async move { let call: Callback = - Callback::EditorCompositor(Box::new(move |_editor, compositor| { + Callback::EditorCompositor(Box::new(move |editor, compositor| { let prompt = debug_parameter_prompt(completions, name, Vec::new()); - compositor.push(Box::new(prompt)); + compositor.push(Box::new(prompt), editor); })); Ok(call) }); @@ -365,9 +365,9 @@ fn debug_parameter_prompt( let params = params.clone(); let callback = Box::pin(async move { let call: Callback = - Callback::EditorCompositor(Box::new(move |_editor, compositor| { + Callback::EditorCompositor(Box::new(move |editor, compositor| { let prompt = debug_parameter_prompt(completions, config_name, params); - compositor.push(Box::new(prompt)); + compositor.push(Box::new(prompt), editor); })); Ok(call) }); @@ -659,7 +659,7 @@ pub fn dap_edit_condition(cx: &mut Context) { if let Some(condition) = breakpoint.condition { prompt.insert_str(&condition, editor) } - compositor.push(Box::new(prompt)); + compositor.push(Box::new(prompt), editor); })); Ok(call) }); @@ -700,7 +700,7 @@ pub fn dap_edit_log(cx: &mut Context) { if let Some(log_message) = breakpoint.log_message { prompt.insert_str(&log_message, editor); } - compositor.push(Box::new(prompt)); + compositor.push(Box::new(prompt), editor); })); Ok(call) }); diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 1f592118014e7..701bfabbe7a57 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -427,9 +427,9 @@ pub fn symbol_picker(cx: &mut Context) { while let Some(mut lsp_items) = futures.try_next().await? { symbols.append(&mut lsp_items); } - let call = move |_editor: &mut Editor, compositor: &mut Compositor| { + let call = move |editor: &mut Editor, compositor: &mut Compositor| { let picker = sym_picker(symbols, current_url); - compositor.push(Box::new(overlaid(picker))) + compositor.push(Box::new(overlaid(picker)), editor) }; Ok(Callback::EditorCompositor(Box::new(call))) @@ -495,10 +495,10 @@ pub fn workspace_symbol_picker(cx: &mut Context) { cx.jobs.callback(async move { let symbols = initial_symbols.await?; - let call = move |_editor: &mut Editor, compositor: &mut Compositor| { + let call = move |editor: &mut Editor, compositor: &mut Compositor| { let picker = sym_picker(symbols, current_url); let dyn_picker = DynamicPicker::new(picker, Box::new(get_symbols)); - compositor.push(Box::new(overlaid(dyn_picker))) + compositor.push(Box::new(overlaid(dyn_picker)), editor) }; Ok(Callback::EditorCompositor(Box::new(call))) @@ -772,7 +772,7 @@ pub fn code_action(cx: &mut Context) { picker.move_down(); // pre-select the first item let popup = Popup::new("code-action", picker).with_scrollbar(false); - compositor.replace_or_push("code-action", popup); + compositor.replace_or_push("code-action", popup, editor); }; Ok(Callback::EditorCompositor(Box::new(call))) @@ -1060,7 +1060,7 @@ fn goto_impl( jump_to_location(cx.editor, location, offset_encoding, action) }) .with_preview(move |_editor, location| Some(location_to_file_location(location))); - compositor.push(Box::new(overlaid(picker))); + compositor.push(Box::new(overlaid(picker)), editor); } } } @@ -1297,7 +1297,7 @@ pub fn signature_help_impl_with_future( return; } - compositor.replace_or_push(SignatureHelp::ID, popup); + compositor.replace_or_push(SignatureHelp::ID, popup, editor); }, ); } @@ -1347,7 +1347,7 @@ pub fn hover(cx: &mut Context) { let contents = ui::Markdown::new(contents, editor.syn_loader.clone()); let popup = Popup::new("hover", contents).auto_close(true); - compositor.replace_or_push("hover", popup); + compositor.replace_or_push("hover", popup, editor); } }, ); @@ -1469,7 +1469,7 @@ pub fn rename_symbol(cx: &mut Context) { let prompt = create_rename_prompt(editor, prefill, Some(ls_id)); - compositor.push(prompt); + compositor.push(prompt, editor); }, ); } else { diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 063658c60a49f..a93c91f931492 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -116,7 +116,7 @@ fn open(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> let call: job::Callback = job::Callback::EditorCompositor(Box::new( move |editor: &mut Editor, compositor: &mut Compositor| { let picker = ui::file_picker(path, &editor.config()); - compositor.push(Box::new(overlaid(picker))); + compositor.push(Box::new(overlaid(picker)), editor); }, )); Ok(call) @@ -1403,11 +1403,11 @@ fn lsp_workspace_command( .collect::>(); let callback = async move { let call: job::Callback = Callback::EditorCompositor(Box::new( - move |_editor: &mut Editor, compositor: &mut Compositor| { + move |editor: &mut Editor, compositor: &mut Compositor| { let picker = ui::Picker::new(commands, (), move |cx, command, _action| { execute_lsp_command(cx.editor, language_server_id, command.clone()); }); - compositor.push(Box::new(overlaid(picker))) + compositor.push(Box::new(overlaid(picker)), editor) }, )); Ok(call) @@ -1532,7 +1532,7 @@ fn tree_sitter_scopes( move |editor: &mut Editor, compositor: &mut Compositor| { let contents = ui::Markdown::new(contents, editor.syn_loader.clone()); let popup = Popup::new("hover", contents).auto_close(true); - compositor.replace_or_push("hover", popup); + compositor.replace_or_push("hover", popup, editor); }, )); Ok(call) @@ -2049,7 +2049,7 @@ fn tree_sitter_subtree( move |editor: &mut Editor, compositor: &mut Compositor| { let contents = ui::Markdown::new(contents, editor.syn_loader.clone()); let popup = Popup::new("hover", contents).auto_close(true); - compositor.replace_or_push("hover", popup); + compositor.replace_or_push("hover", popup, editor); }, )); Ok(call) @@ -2195,7 +2195,7 @@ fn run_shell_command( let popup = Popup::new("shell", contents).position(Some( helix_core::Position::new(editor.cursor().0.unwrap_or_default().row, 2), )); - compositor.replace_or_push("shell", popup); + compositor.replace_or_push("shell", popup, editor); } if success { editor.set_status("Command succeeded"); diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs index bcb3e44904e4e..876554e2f68d9 100644 --- a/helix-term/src/compositor.rs +++ b/helix-term/src/compositor.rs @@ -99,7 +99,8 @@ impl Compositor { } /// Add a layer to be rendered in front of all existing layers. - pub fn push(&mut self, mut layer: Box) { + pub fn push(&mut self, mut layer: Box, editor: &mut Editor) { + editor.reset_idle_timer(); let size = self.size(); // trigger required_size on init layer.required_size((size.width, size.height)); @@ -108,11 +109,16 @@ impl Compositor { /// Replace a component that has the given `id` with the new layer and if /// no component is found, push the layer normally. - pub fn replace_or_push(&mut self, id: &'static str, layer: T) { + pub fn replace_or_push( + &mut self, + id: &'static str, + layer: T, + editor: &mut Editor, + ) { if let Some(component) = self.find_id(id) { *component = layer; } else { - self.push(Box::new(layer)) + self.push(Box::new(layer), editor) } } diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 3359155d5399a..bc8eae52c20f4 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -124,7 +124,7 @@ pub fn regex_prompt( if event == PromptEvent::Validate { let callback = async move { let call: job::Callback = Callback::EditorCompositor(Box::new( - move |_editor: &mut Editor, compositor: &mut Compositor| { + move |editor: &mut Editor, compositor: &mut Compositor| { let contents = Text::new(format!("{}", err)); let size = compositor.size(); let mut popup = Popup::new("invalid-regex", contents) @@ -135,7 +135,11 @@ pub fn regex_prompt( .auto_close(true); popup.required_size((size.width, size.height)); - compositor.replace_or_push("invalid-regex", popup); + compositor.replace_or_push( + "invalid-regex", + popup, + editor, + ); }, )); Ok(call)