Skip to content

Commit

Permalink
reset idle timeout when pushing a new compositor layer
Browse files Browse the repository at this point in the history
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
  • Loading branch information
Philipp-M and pascalkuthe committed Jul 23, 2023
1 parent 48d57da commit 97f310a
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 36 deletions.
4 changes: 2 additions & 2 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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() {
Expand Down
14 changes: 7 additions & 7 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Component>) {
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<T: Component>(&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);
}));
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
},
));
}
Expand All @@ -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")
}
Expand Down
14 changes: 7 additions & 7 deletions helix-term/src/commands/dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn thread_picker(
));
Some((path.into(), pos))
});
compositor.push(Box::new(picker));
compositor.push(Box::new(picker), editor);
},
);
}
Expand Down Expand Up @@ -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)
});
Expand Down Expand Up @@ -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)
});
Expand Down Expand Up @@ -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)
});
Expand Down Expand Up @@ -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)
});
Expand Down
18 changes: 9 additions & 9 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
},
);
}
Expand Down Expand Up @@ -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);
}
},
);
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn open(cx: &mut compositor::Context, args: &[Cow<str>], 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)
Expand Down Expand Up @@ -1403,11 +1403,11 @@ fn lsp_workspace_command(
.collect::<Vec<_>>();
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down
12 changes: 9 additions & 3 deletions helix-term/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Component>) {
pub fn push(&mut self, mut layer: Box<dyn Component>, editor: &mut Editor) {
editor.reset_idle_timer();
let size = self.size();
// trigger required_size on init
layer.required_size((size.width, size.height));
Expand All @@ -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<T: Component>(&mut self, id: &'static str, layer: T) {
pub fn replace_or_push<T: Component>(
&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)
}
}

Expand Down
8 changes: 6 additions & 2 deletions helix-term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 97f310a

Please sign in to comment.