on master help sign in
Remove more push_layer calls
96a4eb8Blaž Hrastnik
helix-term/src/commands.rs+15−20
@@ -2187,7 +2187,7 @@ async fn make_format_callback(
2187 format: impl Future<Output = helix_lsp::util::LspFormatting> + Send + 'static,
2187 format: impl Future<Output = helix_lsp::util::LspFormatting> + Send + 'static,
2188) -> anyhow::Result<job::Callback> {
2188) -> anyhow::Result<job::Callback> {
2189 let format = format.await;
2189 let format = format.await;
2190− let call: job::Callback = Box::new(move |editor: &mut Editor, _compositor: &mut Compositor| {
2190+ let call: job::Callback = Box::new(move |editor, _compositor| {
2191 let view_id = view!(editor).id;
2191 let view_id = view!(editor).id;
2192 if let Some(doc) = editor.document_mut(doc_id) {
2192 if let Some(doc) = editor.document_mut(doc_id) {
2193 if doc.version() == doc_version {
2193 if doc.version() == doc_version {
@@ -3475,9 +3475,7 @@ pub fn completion(cx: &mut Context) {
3475
3475
3476 cx.callback(
3476 cx.callback(
3477 future,
3477 future,
3478− move |editor: &mut Editor,
3479− compositor: &mut Compositor,
3480− response: Option<lsp::CompletionResponse>| {
3478+ move |editor, compositor, response: Option<lsp::CompletionResponse>| {
3481 let doc = doc!(editor);
3479 let doc = doc!(editor);
3482 if doc.mode() != Mode::Insert {
3480 if doc.mode() != Mode::Insert {
3483 // we're not in insert mode anymore
3481 // we're not in insert mode anymore
@@ -4123,11 +4121,12 @@ fn shell_append_output(cx: &mut Context) {
4123}
4121}
4124
4122
4125fn shell_keep_pipe(cx: &mut Context) {
4123fn shell_keep_pipe(cx: &mut Context) {
4126− let prompt = Prompt::new(
4124+ ui::prompt(
4125+ cx,
4127 "keep-pipe:".into(),
4126 "keep-pipe:".into(),
4128 Some('|'),
4127 Some('|'),
4129 ui::completers::none,
4128 ui::completers::none,
4130− move |cx: &mut compositor::Context, input: &str, event: PromptEvent| {
4129+ move |cx, input: &str, event: PromptEvent| {
4131 let shell = &cx.editor.config().shell;
4130 let shell = &cx.editor.config().shell;
4132 if event != PromptEvent::Validate {
4131 if event != PromptEvent::Validate {
4133 return;
4132 return;
@@ -4171,8 +4170,6 @@ fn shell_keep_pipe(cx: &mut Context) {
4171 doc.set_selection(view.id, Selection::new(ranges, index));
4170 doc.set_selection(view.id, Selection::new(ranges, index));
4172 },
4171 },
4173 );
4172 );
4174−
4175− cx.push_layer(Box::new(prompt));
4176}
4173}
4177
4174
4178fn shell_impl(
4175fn shell_impl(
@@ -4219,11 +4216,13 @@ fn shell(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBehavior) {
4219 ShellBehavior::Replace | ShellBehavior::Ignore => true,
4216 ShellBehavior::Replace | ShellBehavior::Ignore => true,
4220 ShellBehavior::Insert | ShellBehavior::Append => false,
4217 ShellBehavior::Insert | ShellBehavior::Append => false,
4221 };
4218 };
4219+
4222− let prompt = Prompt::new(
4220+ ui::prompt(
4221+ cx,
4223 prompt,
4222 prompt,
4224 Some('|'),
4223 Some('|'),
4225 ui::completers::none,
4224 ui::completers::none,
4226− move |cx: &mut compositor::Context, input: &str, event: PromptEvent| {
4225+ move |cx, input: &str, event: PromptEvent| {
4227 let config = cx.editor.config();
4226 let config = cx.editor.config();
4228 let shell = &config.shell;
4227 let shell = &config.shell;
4229 if event != PromptEvent::Validate {
4228 if event != PromptEvent::Validate {
@@ -4273,8 +4272,6 @@ fn shell(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBehavior) {
4273 view.ensure_cursor_in_view(doc, config.scrolloff);
4272 view.ensure_cursor_in_view(doc, config.scrolloff);
4274 },
4273 },
4275 );
4274 );
4276−
4277− cx.push_layer(Box::new(prompt));
4278}
4275}
4279
4276
4280fn suspend(_cx: &mut Context) {
4277fn suspend(_cx: &mut Context) {
@@ -4420,13 +4417,11 @@ fn replay_macro(cx: &mut Context) {
4420 };
4417 };
4421
4418
4422 let count = cx.count();
4419 let count = cx.count();
4423− cx.callback = Some(Box::new(
4420+ cx.callback = Some(Box::new(move |compositor, cx| {
4424− move |compositor: &mut Compositor, cx: &mut compositor::Context| {
4425− for _ in 0..count {
4421+ for _ in 0..count {
4426− for &key in keys.iter() {
4422+ for &key in keys.iter() {
4427− compositor.handle_event(crossterm::event::Event::Key(key.into()), cx);
4423+ compositor.handle_event(crossterm::event::Event::Key(key.into()), cx);
4428− }
4429 }
4424 }
4430− },
4425+ }
4431− ));
4426+ }));
4432}
4427}
helix-term/src/commands/lsp.rs+7−13
@@ -11,7 +11,7 @@ use helix_view::editor::Action;
11
11
12use crate::{
12use crate::{
13 compositor::{self, Compositor},
13 compositor::{self, Compositor},
14− ui::{self, overlay::overlayed, FileLocation, FilePicker, Popup, Prompt, PromptEvent},
14+ ui::{self, overlay::overlayed, FileLocation, FilePicker, Popup, PromptEvent},
15};
15};
16
16
17use std::borrow::Cow;
17use std::borrow::Cow;
@@ -138,9 +138,7 @@ pub fn symbol_picker(cx: &mut Context) {
138
138
139 cx.callback(
139 cx.callback(
140 future,
140 future,
141− move |editor: &mut Editor,
142− compositor: &mut Compositor,
143− response: Option<lsp::DocumentSymbolResponse>| {
141+ move |editor, compositor, response: Option<lsp::DocumentSymbolResponse>| {
144 if let Some(symbols) = response {
142 if let Some(symbols) = response {
145 // lsp has two ways to represent symbols (flat/nested)
143 // lsp has two ways to represent symbols (flat/nested)
146 // convert the nested variant to flat, so that we have a homogeneous list
144 // 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) {
172
170
173 cx.callback(
171 cx.callback(
174 future,
172 future,
175− move |_editor: &mut Editor,
176− compositor: &mut Compositor,
177− response: Option<Vec<lsp::SymbolInformation>>| {
173+ move |_editor, compositor, response: Option<Vec<lsp::SymbolInformation>>| {
178 if let Some(symbols) = response {
174 if let Some(symbols) = response {
179 let picker = sym_picker(symbols, current_url, offset_encoding);
175 let picker = sym_picker(symbols, current_url, offset_encoding);
180 compositor.push(Box::new(overlayed(picker)))
176 compositor.push(Box::new(overlayed(picker)))
@@ -208,9 +204,7 @@ pub fn code_action(cx: &mut Context) {
208
204
209 cx.callback(
205 cx.callback(
210 future,
206 future,
211− move |editor: &mut Editor,
212− compositor: &mut Compositor,
213− response: Option<lsp::CodeActionResponse>| {
207+ move |editor, compositor, response: Option<lsp::CodeActionResponse>| {
214 let actions = match response {
208 let actions = match response {
215 Some(a) => a,
209 Some(a) => a,
216 None => return,
210 None => return,
@@ -613,7 +607,7 @@ pub fn hover(cx: &mut Context) {
613
607
614 cx.callback(
608 cx.callback(
615 future,
609 future,
616− move |editor: &mut Editor, compositor: &mut Compositor, response: Option<lsp::Hover>| {
610+ move |editor, compositor, response: Option<lsp::Hover>| {
617 if let Some(hover) = response {
611 if let Some(hover) = response {
618 // hover.contents / .range <- used for visualizing
612 // hover.contents / .range <- used for visualizing
619
613
@@ -650,7 +644,8 @@ pub fn hover(cx: &mut Context) {
650 );
644 );
651}
645}
652pub fn rename_symbol(cx: &mut Context) {
646pub fn rename_symbol(cx: &mut Context) {
653− let prompt = Prompt::new(
647+ ui::prompt(
648+ cx,
654 "rename-to:".into(),
649 "rename-to:".into(),
655 None,
650 None,
656 ui::completers::none,
651 ui::completers::none,
@@ -670,5 +665,4 @@ pub fn rename_symbol(cx: &mut Context) {
670 apply_workspace_edit(cx.editor, offset_encoding, &edits);
665 apply_workspace_edit(cx.editor, offset_encoding, &edits);
671 },
666 },
672 );
667 );
673− cx.push_layer(Box::new(prompt));
674}
668}
helix-term/src/ui/mod.rs+13
@@ -26,6 +26,19 @@ use helix_view::{Document, Editor, View};
26
26
27use std::path::PathBuf;
27use std::path::PathBuf;
28
28
29+pub fn prompt(
30+ cx: &mut crate::commands::Context,
31+ prompt: std::borrow::Cow<'static, str>,
32+ history_register: Option<char>,
33+ completion_fn: impl FnMut(&Editor, &str) -> Vec<prompt::Completion> + 'static,
34+ callback_fn: impl FnMut(&mut crate::compositor::Context, &str, PromptEvent) + 'static,
35+) {
36+ let mut prompt = Prompt::new(prompt, history_register, completion_fn, callback_fn);
37+ // Calculate initial completion
38+ prompt.recalculate_completion(cx.editor);
39+ cx.push_layer(Box::new(prompt));
40+}
41+
29pub fn regex_prompt(
42pub fn regex_prompt(
30 cx: &mut crate::commands::Context,
43 cx: &mut crate::commands::Context,
31 prompt: std::borrow::Cow<'static, str>,
44 prompt: std::borrow::Cow<'static, str>,