on master help sign in
Make picker take the whole context, not just editor
3b8d510Blaž Hrastnik
helix-term/src/commands.rs+13−15
@@ -1458,11 +1458,11 @@ fn global_search(cx: &mut Context) {
1458 relative_path.into()
1458 relative_path.into()
1459 }
1459 }
1460 },
1460 },
1461− move |editor: &mut Editor, (line_num, path), action| {
1461+ move |cx, (line_num, path), action| {
1462− match editor.open(path.into(), action) {
1462+ match cx.editor.open(path.into(), action) {
1463 Ok(_) => {}
1463 Ok(_) => {}
1464 Err(e) => {
1464 Err(e) => {
1465− editor.set_error(format!(
1465+ cx.editor.set_error(format!(
1466 "Failed to open file '{}': {}",
1466 "Failed to open file '{}': {}",
1467 path.display(),
1467 path.display(),
1468 e
1468 e
@@ -1472,7 +1472,7 @@ fn global_search(cx: &mut Context) {
1472 }
1472 }
1473
1473
1474 let line_num = *line_num;
1474 let line_num = *line_num;
1475− let (view, doc) = current!(editor);
1475+ let (view, doc) = current!(cx.editor);
1476 let text = doc.text();
1476 let text = doc.text();
1477 let start = text.line_to_char(line_num);
1477 let start = text.line_to_char(line_num);
1478 let end = text.line_to_char((line_num + 1).min(text.len_lines()));
1478 let end = text.line_to_char((line_num + 1).min(text.len_lines()));
@@ -2717,8 +2717,8 @@ fn buffer_picker(cx: &mut Context) {
2717 None => "[scratch buffer]".into(),
2717 None => "[scratch buffer]".into(),
2718 }
2718 }
2719 },
2719 },
2720− |editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
2720+ |cx, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
2721− editor.switch(*id, Action::Replace);
2721+ cx.editor.switch(*id, Action::Replace);
2722 },
2722 },
2723 |editor, (id, path)| {
2723 |editor, (id, path)| {
2724 let doc = &editor.documents.get(id)?;
2724 let doc = &editor.documents.get(id)?;
@@ -2785,9 +2785,9 @@ fn symbol_picker(cx: &mut Context) {
2785 let picker = FilePicker::new(
2785 let picker = FilePicker::new(
2786 symbols,
2786 symbols,
2787 |symbol| (&symbol.name).into(),
2787 |symbol| (&symbol.name).into(),
2788− move |editor: &mut Editor, symbol, _action| {
2788+ move |cx, symbol, _action| {
2789− push_jump(editor);
2789+ push_jump(cx.editor);
2790− let (view, doc) = current!(editor);
2790+ let (view, doc) = current!(cx.editor);
2791
2791
2792 if let Some(range) =
2792 if let Some(range) =
2793 lsp_range_to_range(doc.text(), symbol.location.range, offset_encoding)
2793 lsp_range_to_range(doc.text(), symbol.location.range, offset_encoding)
@@ -2845,15 +2845,15 @@ pub fn code_action(cx: &mut Context) {
2845 }
2845 }
2846 lsp::CodeActionOrCommand::Command(command) => command.title.as_str().into(),
2846 lsp::CodeActionOrCommand::Command(command) => command.title.as_str().into(),
2847 },
2847 },
2848− move |editor, code_action, _action| match code_action {
2848+ move |cx, code_action, _action| match code_action {
2849 lsp::CodeActionOrCommand::Command(command) => {
2849 lsp::CodeActionOrCommand::Command(command) => {
2850 log::debug!("code action command: {:?}", command);
2850 log::debug!("code action command: {:?}", command);
2851− editor.set_error(String::from("Handling code action command is not implemented yet, see https://github.com/helix-editor/helix/issues/183"));
2851+ cx.editor.set_error(String::from("Handling code action command is not implemented yet, see https://github.com/helix-editor/helix/issues/183"));
2852 }
2852 }
2853 lsp::CodeActionOrCommand::CodeAction(code_action) => {
2853 lsp::CodeActionOrCommand::CodeAction(code_action) => {
2854 log::debug!("code action: {:?}", code_action);
2854 log::debug!("code action: {:?}", code_action);
2855 if let Some(ref workspace_edit) = code_action.edit {
2855 if let Some(ref workspace_edit) = code_action.edit {
2856− apply_workspace_edit(editor, offset_encoding, workspace_edit)
2856+ apply_workspace_edit(cx.editor, offset_encoding, workspace_edit)
2857 }
2857 }
2858 }
2858 }
2859 },
2859 },
@@ -3267,9 +3267,7 @@ fn goto_impl(
3267 let line = location.range.start.line;
3267 let line = location.range.start.line;
3268 format!("{}:{}", file, line).into()
3268 format!("{}:{}", file, line).into()
3269 },
3269 },
3270− move |editor: &mut Editor, location, action| {
3271− jump_to(editor, location, offset_encoding, action)
3270+ move |cx, location, action| jump_to(cx.editor, location, offset_encoding, action),
3272− },
3273 |_editor, location| {
3271 |_editor, location| {
3274 let path = location.uri.to_file_path().unwrap();
3272 let path = location.uri.to_file_path().unwrap();
3275 let line = Some((
3273 let line = Some((
helix-term/src/commands/dap.rs+6−6
@@ -128,7 +128,7 @@ fn thread_picker(cx: &mut Context, callback_fn: impl Fn(&mut Editor, &dap::Threa
128 )
128 )
129 .into()
129 .into()
130 },
130 },
131− move |editor, thread, _action| callback_fn(editor, thread),
131+ move |cx, thread, _action| callback_fn(cx.editor, thread),
132 move |_editor, thread| {
132 move |_editor, thread| {
133 if let Some(frame) = frames.get(&thread.id).and_then(|bt| bt.get(0)) {
133 if let Some(frame) = frames.get(&thread.id).and_then(|bt| bt.get(0)) {
134 frame
134 frame
@@ -323,9 +323,9 @@ pub fn dap_launch(cx: &mut Context) {
323 true,
323 true,
324 config.templates,
324 config.templates,
325 |template| template.name.as_str().into(),
325 |template| template.name.as_str().into(),
326− |editor, template, _action| {
326+ |cx, template, _action| {
327 let completions = template.completion.clone();
327 let completions = template.completion.clone();
328− editor.debug_config_completions = completions;
328+ cx.editor.debug_config_completions = completions;
329 // TODO: need some way to manipulate the compositor to push a new prompt here
329 // TODO: need some way to manipulate the compositor to push a new prompt here
330 },
330 },
331 ))); // TODO: wrap in popup with fixed size
331 ))); // TODO: wrap in popup with fixed size
@@ -755,8 +755,8 @@ pub fn dap_switch_stack_frame(cx: &mut Context) {
755 let picker = FilePicker::new(
755 let picker = FilePicker::new(
756 frames,
756 frames,
757 |frame| frame.name.clone().into(), // TODO: include thread_states in the label
757 |frame| frame.name.clone().into(), // TODO: include thread_states in the label
758− move |editor, frame, _action| {
758+ move |cx, frame, _action| {
759− let debugger = match &mut editor.debugger {
759+ let debugger = match &mut cx.editor.debugger {
760 Some(debugger) => debugger,
760 Some(debugger) => debugger,
761 None => return,
761 None => return,
762 };
762 };
@@ -770,7 +770,7 @@ pub fn dap_switch_stack_frame(cx: &mut Context) {
770 .get(pos.unwrap_or(0))
770 .get(pos.unwrap_or(0))
771 .cloned();
771 .cloned();
772 if let Some(frame) = &frame {
772 if let Some(frame) = &frame {
773− jump_to_stack_frame(editor, frame);
773+ jump_to_stack_frame(cx.editor, frame);
774 }
774 }
775 },
775 },
776 move |_editor, frame| {
776 move |_editor, frame| {
helix-term/src/ui/mod.rs+3−3
@@ -21,7 +21,7 @@ pub use text::Text;
21
21
22use helix_core::regex::Regex;
22use helix_core::regex::Regex;
23use helix_core::regex::RegexBuilder;
23use helix_core::regex::RegexBuilder;
24−use helix_view::{Document, Editor, View};
24+use helix_view::{Document, View};
25
25
26use std::path::PathBuf;
26use std::path::PathBuf;
27
27
@@ -151,8 +151,8 @@ pub fn file_picker(root: PathBuf) -> FilePicker<PathBuf> {
151 .unwrap()
151 .unwrap()
152 .into()
152 .into()
153 },
153 },
154− move |editor: &mut Editor, path: &PathBuf, action| {
154+ move |cx, path: &PathBuf, action| {
155− editor
155+ cx.editor
156 .open(path.into(), action)
156 .open(path.into(), action)
157 .expect("editor.open failed");
157 .expect("editor.open failed");
158 },
158 },
helix-term/src/ui/picker.rs+6−6
@@ -84,7 +84,7 @@ impl<T> FilePicker<T> {
84 pub fn new(
84 pub fn new(
85 options: Vec<T>,
85 options: Vec<T>,
86 format_fn: impl Fn(&T) -> Cow<str> + 'static,
86 format_fn: impl Fn(&T) -> Cow<str> + 'static,
87− callback_fn: impl Fn(&mut Editor, &T, Action) + 'static,
87+ callback_fn: impl Fn(&mut Context, &T, Action) + 'static,
88 preview_fn: impl Fn(&Editor, &T) -> Option<FileLocation> + 'static,
88 preview_fn: impl Fn(&Editor, &T) -> Option<FileLocation> + 'static,
89 ) -> Self {
89 ) -> Self {
90 Self {
90 Self {
@@ -278,7 +278,7 @@ pub struct Picker<T> {
278 render_centered: bool,
278 render_centered: bool,
279
279
280 format_fn: Box<dyn Fn(&T) -> Cow<str>>,
280 format_fn: Box<dyn Fn(&T) -> Cow<str>>,
281− callback_fn: Box<dyn Fn(&mut Editor, &T, Action)>,
281+ callback_fn: Box<dyn Fn(&mut Context, &T, Action)>,
282}
282}
283
283
284impl<T> Picker<T> {
284impl<T> Picker<T> {
@@ -286,7 +286,7 @@ impl<T> Picker<T> {
286 render_centered: bool,
286 render_centered: bool,
287 options: Vec<T>,
287 options: Vec<T>,
288 format_fn: impl Fn(&T) -> Cow<str> + 'static,
288 format_fn: impl Fn(&T) -> Cow<str> + 'static,
289− callback_fn: impl Fn(&mut Editor, &T, Action) + 'static,
289+ callback_fn: impl Fn(&mut Context, &T, Action) + 'static,
290 ) -> Self {
290 ) -> Self {
291 let prompt = Prompt::new(
291 let prompt = Prompt::new(
292 "".into(),
292 "".into(),
@@ -452,7 +452,7 @@ impl<T: 'static> Component for Picker<T> {
452 ..
452 ..
453 } => {
453 } => {
454 if let Some(option) = self.selection() {
454 if let Some(option) = self.selection() {
455− (self.callback_fn)(&mut cx.editor, option, Action::Replace);
455+ (self.callback_fn)(cx, option, Action::Replace);
456 }
456 }
457 return close_fn;
457 return close_fn;
458 }
458 }
@@ -461,7 +461,7 @@ impl<T: 'static> Component for Picker<T> {
461 modifiers: KeyModifiers::CONTROL,
461 modifiers: KeyModifiers::CONTROL,
462 } => {
462 } => {
463 if let Some(option) = self.selection() {
463 if let Some(option) = self.selection() {
464− (self.callback_fn)(&mut cx.editor, option, Action::HorizontalSplit);
464+ (self.callback_fn)(cx, option, Action::HorizontalSplit);
465 }
465 }
466 return close_fn;
466 return close_fn;
467 }
467 }
@@ -470,7 +470,7 @@ impl<T: 'static> Component for Picker<T> {
470 modifiers: KeyModifiers::CONTROL,
470 modifiers: KeyModifiers::CONTROL,
471 } => {
471 } => {
472 if let Some(option) = self.selection() {
472 if let Some(option) = self.selection() {
473− (self.callback_fn)(&mut cx.editor, option, Action::VerticalSplit);
473+ (self.callback_fn)(cx, option, Action::VerticalSplit);
474 }
474 }
475 return close_fn;
475 return close_fn;
476 }
476 }