Skip to content

Commit

Permalink
reset idle timeout when pushing a new composistor layer
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalkuthe committed Jan 24, 2023
1 parent d14de27 commit 15f4c01
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 31 deletions.
4 changes: 2 additions & 2 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,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_dir().join("tutor");
Expand All @@ -194,7 +194,7 @@ impl Application {
std::env::set_current_dir(first).context("set current dir")?;
editor.new_file(Action::VerticalSplit);
let picker = ui::file_picker(".".into(), &config.load().editor);
compositor.push(Box::new(overlayed(picker)));
compositor.push(Box::new(overlayed(picker)), &mut editor);
} else {
let nr_of_files = args.files.len();
for (i, (file, pos)) in args.files.into_iter().enumerate() {
Expand Down
10 changes: 5 additions & 5 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ 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)
}));
}

Expand Down Expand Up @@ -2008,7 +2008,7 @@ fn global_search(cx: &mut Context) {
Some((path.clone().into(), Some((*line_num, *line_num))))
},
);
compositor.push(Box::new(overlayed(picker)));
compositor.push(Box::new(overlayed(picker)), editor);
},
));
Ok(call)
Expand Down Expand Up @@ -2504,7 +2504,7 @@ pub fn command_palette(cx: &mut Context) {
};
command.execute(&mut ctx);
});
compositor.push(Box::new(overlayed(picker)));
compositor.push(Box::new(overlayed(picker)), cx.editor);
},
));
}
Expand All @@ -2513,7 +2513,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 @@ -88,7 +88,7 @@ fn thread_picker(
Some((path.into(), pos))
},
);
compositor.push(Box::new(picker));
compositor.push(Box::new(picker), editor);
},
);
}
Expand Down Expand Up @@ -278,9 +278,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 @@ -337,9 +337,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 @@ -614,7 +614,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 @@ -655,7 +655,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
14 changes: 7 additions & 7 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ pub fn symbol_picker(cx: &mut Context) {
};

let picker = sym_picker(symbols, current_url, offset_encoding);
compositor.push(Box::new(overlayed(picker)))
compositor.push(Box::new(overlayed(picker)), editor)
}
},
)
Expand All @@ -383,10 +383,10 @@ pub fn workspace_symbol_picker(cx: &mut Context) {

cx.callback(
future,
move |_editor, compositor, response: Option<Vec<lsp::SymbolInformation>>| {
move |editor, compositor, response: Option<Vec<lsp::SymbolInformation>>| {
if let Some(symbols) = response {
let picker = sym_picker(symbols, current_url, offset_encoding);
compositor.push(Box::new(overlayed(picker)))
compositor.push(Box::new(overlayed(picker)), editor)
}
},
)
Expand Down Expand Up @@ -620,7 +620,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);
},
)
}
Expand Down Expand Up @@ -855,7 +855,7 @@ fn goto_impl(
},
move |_editor, location| Some(location_to_file_location(location)),
);
compositor.push(Box::new(overlayed(picker)));
compositor.push(Box::new(overlayed(picker)), editor);
}
}
}
Expand Down Expand Up @@ -1100,7 +1100,7 @@ pub fn signature_help_impl(cx: &mut Context, invoked: SignatureHelpInvoked) {
.position(old_popup.and_then(|p| p.get_position()))
.position_bias(Open::Above)
.ignore_escape_key(true);
compositor.replace_or_push(SignatureHelp::ID, popup);
compositor.replace_or_push(SignatureHelp::ID, popup, editor);
},
);
}
Expand Down Expand Up @@ -1156,7 +1156,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
10 changes: 5 additions & 5 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,11 +1144,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, (), |cx, command, _action| {
execute_lsp_command(cx.editor, command.clone());
});
compositor.push(Box::new(overlayed(picker)))
compositor.push(Box::new(overlayed(picker)), editor)
},
));
Ok(call)
Expand Down Expand Up @@ -1231,7 +1231,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 @@ -1660,7 +1660,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 @@ -1779,7 +1779,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);
},
));
Ok(call)
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 @@ -97,7 +97,8 @@ impl Compositor {
self.area = area;
}

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 @@ -106,11 +107,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 @@ -122,7 +122,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 @@ -133,7 +133,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 15f4c01

Please sign in to comment.