aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorBlaž Hrastnik2022-03-22 14:25:40 +0000
committerBlaž Hrastnik2022-03-28 02:02:21 +0000
commit96a4eb84838d4cbfb9313968278985ea1986a3bc (patch)
tree24506b4194cae8028130727933be8c640b7e54cf /helix-term
parent5c162ef995e3822cd465f2c83874a040ebe153b8 (diff)
Remove more push_layer calls
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs35
-rw-r--r--helix-term/src/commands/lsp.rs20
-rw-r--r--helix-term/src/ui/mod.rs13
3 files changed, 35 insertions, 33 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 7de4d7eb..01d20b28 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -2187,7 +2187,7 @@ async fn make_format_callback(
format: impl Future<Output = helix_lsp::util::LspFormatting> + Send + 'static,
) -> anyhow::Result<job::Callback> {
let format = format.await;
- let call: job::Callback = Box::new(move |editor: &mut Editor, _compositor: &mut Compositor| {
+ let call: job::Callback = Box::new(move |editor, _compositor| {
let view_id = view!(editor).id;
if let Some(doc) = editor.document_mut(doc_id) {
if doc.version() == doc_version {
@@ -3475,9 +3475,7 @@ pub fn completion(cx: &mut Context) {
cx.callback(
future,
- move |editor: &mut Editor,
- compositor: &mut Compositor,
- response: Option<lsp::CompletionResponse>| {
+ move |editor, compositor, response: Option<lsp::CompletionResponse>| {
let doc = doc!(editor);
if doc.mode() != Mode::Insert {
// we're not in insert mode anymore
@@ -4123,11 +4121,12 @@ fn shell_append_output(cx: &mut Context) {
}
fn shell_keep_pipe(cx: &mut Context) {
- let prompt = Prompt::new(
+ ui::prompt(
+ cx,
"keep-pipe:".into(),
Some('|'),
ui::completers::none,
- move |cx: &mut compositor::Context, input: &str, event: PromptEvent| {
+ move |cx, input: &str, event: PromptEvent| {
let shell = &cx.editor.config().shell;
if event != PromptEvent::Validate {
return;
@@ -4171,8 +4170,6 @@ fn shell_keep_pipe(cx: &mut Context) {
doc.set_selection(view.id, Selection::new(ranges, index));
},
);
-
- cx.push_layer(Box::new(prompt));
}
fn shell_impl(
@@ -4219,11 +4216,13 @@ fn shell(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBehavior) {
ShellBehavior::Replace | ShellBehavior::Ignore => true,
ShellBehavior::Insert | ShellBehavior::Append => false,
};
- let prompt = Prompt::new(
+
+ ui::prompt(
+ cx,
prompt,
Some('|'),
ui::completers::none,
- move |cx: &mut compositor::Context, input: &str, event: PromptEvent| {
+ move |cx, input: &str, event: PromptEvent| {
let config = cx.editor.config();
let shell = &config.shell;
if event != PromptEvent::Validate {
@@ -4273,8 +4272,6 @@ fn shell(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBehavior) {
view.ensure_cursor_in_view(doc, config.scrolloff);
},
);
-
- cx.push_layer(Box::new(prompt));
}
fn suspend(_cx: &mut Context) {
@@ -4420,13 +4417,11 @@ fn replay_macro(cx: &mut Context) {
};
let count = cx.count();
- cx.callback = Some(Box::new(
- move |compositor: &mut Compositor, cx: &mut compositor::Context| {
- for _ in 0..count {
- for &key in keys.iter() {
- compositor.handle_event(crossterm::event::Event::Key(key.into()), cx);
- }
+ cx.callback = Some(Box::new(move |compositor, cx| {
+ for _ in 0..count {
+ for &key in keys.iter() {
+ compositor.handle_event(crossterm::event::Event::Key(key.into()), cx);
}
- },
- ));
+ }
+ }));
}
diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs
index 308ff829..530e528a 100644
--- a/helix-term/src/commands/lsp.rs
+++ b/helix-term/src/commands/lsp.rs
@@ -11,7 +11,7 @@ use helix_view::editor::Action;
use crate::{
compositor::{self, Compositor},
- ui::{self, overlay::overlayed, FileLocation, FilePicker, Popup, Prompt, PromptEvent},
+ ui::{self, overlay::overlayed, FileLocation, FilePicker, Popup, PromptEvent},
};
use std::borrow::Cow;
@@ -138,9 +138,7 @@ pub fn symbol_picker(cx: &mut Context) {
cx.callback(
future,
- move |editor: &mut Editor,
- compositor: &mut Compositor,
- response: Option<lsp::DocumentSymbolResponse>| {
+ move |editor, compositor, response: Option<lsp::DocumentSymbolResponse>| {
if let Some(symbols) = response {
// lsp has two ways to represent symbols (flat/nested)
// convert the nested variant to flat, so that we have a homogeneous list
@@ -172,9 +170,7 @@ pub fn workspace_symbol_picker(cx: &mut Context) {
cx.callback(
future,
- move |_editor: &mut Editor,
- compositor: &mut 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)))
@@ -208,9 +204,7 @@ pub fn code_action(cx: &mut Context) {
cx.callback(
future,
- move |editor: &mut Editor,
- compositor: &mut Compositor,
- response: Option<lsp::CodeActionResponse>| {
+ move |editor, compositor, response: Option<lsp::CodeActionResponse>| {
let actions = match response {
Some(a) => a,
None => return,
@@ -613,7 +607,7 @@ pub fn hover(cx: &mut Context) {
cx.callback(
future,
- move |editor: &mut Editor, compositor: &mut Compositor, response: Option<lsp::Hover>| {
+ move |editor, compositor, response: Option<lsp::Hover>| {
if let Some(hover) = response {
// hover.contents / .range <- used for visualizing
@@ -650,7 +644,8 @@ pub fn hover(cx: &mut Context) {
);
}
pub fn rename_symbol(cx: &mut Context) {
- let prompt = Prompt::new(
+ ui::prompt(
+ cx,
"rename-to:".into(),
None,
ui::completers::none,
@@ -670,5 +665,4 @@ pub fn rename_symbol(cx: &mut Context) {
apply_workspace_edit(cx.editor, offset_encoding, &edits);
},
);
- cx.push_layer(Box::new(prompt));
}
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index 3c39a517..a90debdb 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -26,6 +26,19 @@ use helix_view::{Document, Editor, View};
use std::path::PathBuf;
+pub fn prompt(
+ cx: &mut crate::commands::Context,
+ prompt: std::borrow::Cow<'static, str>,
+ history_register: Option<char>,
+ completion_fn: impl FnMut(&Editor, &str) -> Vec<prompt::Completion> + 'static,
+ callback_fn: impl FnMut(&mut crate::compositor::Context, &str, PromptEvent) + 'static,
+) {
+ let mut prompt = Prompt::new(prompt, history_register, completion_fn, callback_fn);
+ // Calculate initial completion
+ prompt.recalculate_completion(cx.editor);
+ cx.push_layer(Box::new(prompt));
+}
+
pub fn regex_prompt(
cx: &mut crate::commands::Context,
prompt: std::borrow::Cow<'static, str>,