on master help sign in
Make picker take the whole context, not just editor
commit3b8d5102acfcd2aeacb7d8c88eaaf51f5be0cc7b authorBlaž Hrastnik <blaz@mxxn.io> dateSun 7 Nov 2021, 18:03 (5 years ago) parent64bb1f7
4 files changed+28−30
helix-term/src/commands.rs+13−15 helix-term/src/commands/dap.rs+6−6 helix-term/src/ui/mod.rs+3−3 helix-term/src/ui/picker.rs+6−6
helix-term/src/commands.rs+13−15
@@ -1458,11 +1458,11 @@ fn global_search(cx: &mut Context) {
14581458 relative_path.into()
14591459 }
14601460 },
1461− move |editor: &mut Editor, (line_num, path), action| {
1462− match editor.open(path.into(), action) {
1461+ move |cx, (line_num, path), action| {
1462+ match cx.editor.open(path.into(), action) {
14631463 Ok(_) => {}
14641464 Err(e) => {
1465− editor.set_error(format!(
1465+ cx.editor.set_error(format!(
14661466 "Failed to open file '{}': {}",
14671467 path.display(),
14681468 e
@@ -1472,7 +1472,7 @@ fn global_search(cx: &mut Context) {
14721472 }
14731473
14741474 let line_num = *line_num;
1475− let (view, doc) = current!(editor);
1475+ let (view, doc) = current!(cx.editor);
14761476 let text = doc.text();
14771477 let start = text.line_to_char(line_num);
14781478 let end = text.line_to_char((line_num + 1).min(text.len_lines()));
@@ -2717,8 +2717,8 @@ fn buffer_picker(cx: &mut Context) {
27172717 None => "[scratch buffer]".into(),
27182718 }
27192719 },
2720− |editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
2721− editor.switch(*id, Action::Replace);
2720+ |cx, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
2721+ cx.editor.switch(*id, Action::Replace);
27222722 },
27232723 |editor, (id, path)| {
27242724 let doc = &editor.documents.get(id)?;
@@ -2785,9 +2785,9 @@ fn symbol_picker(cx: &mut Context) {
27852785 let picker = FilePicker::new(
27862786 symbols,
27872787 |symbol| (&symbol.name).into(),
2788− move |editor: &mut Editor, symbol, _action| {
2789− push_jump(editor);
2790− let (view, doc) = current!(editor);
2788+ move |cx, symbol, _action| {
2789+ push_jump(cx.editor);
2790+ let (view, doc) = current!(cx.editor);
27912791
27922792 if let Some(range) =
27932793 lsp_range_to_range(doc.text(), symbol.location.range, offset_encoding)
@@ -2845,15 +2845,15 @@ pub fn code_action(cx: &mut Context) {
28452845 }
28462846 lsp::CodeActionOrCommand::Command(command) => command.title.as_str().into(),
28472847 },
2848− move |editor, code_action, _action| match code_action {
2848+ move |cx, code_action, _action| match code_action {
28492849 lsp::CodeActionOrCommand::Command(command) => {
28502850 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"));
28522852 }
28532853 lsp::CodeActionOrCommand::CodeAction(code_action) => {
28542854 log::debug!("code action: {:?}", code_action);
28552855 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)
28572857 }
28582858 }
28592859 },
@@ -3267,9 +3267,7 @@ fn goto_impl(
32673267 let line = location.range.start.line;
32683268 format!("{}:{}", file, line).into()
32693269 },
3270− move |editor: &mut Editor, location, action| {
3271− jump_to(editor, location, offset_encoding, action)
3272− },
3270+ move |cx, location, action| jump_to(cx.editor, location, offset_encoding, action),
32733271 |_editor, location| {
32743272 let path = location.uri.to_file_path().unwrap();
32753273 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
128128 )
129129 .into()
130130 },
131− move |editor, thread, _action| callback_fn(editor, thread),
131+ move |cx, thread, _action| callback_fn(cx.editor, thread),
132132 move |_editor, thread| {
133133 if let Some(frame) = frames.get(&thread.id).and_then(|bt| bt.get(0)) {
134134 frame
@@ -323,9 +323,9 @@ pub fn dap_launch(cx: &mut Context) {
323323 true,
324324 config.templates,
325325 |template| template.name.as_str().into(),
326− |editor, template, _action| {
326+ |cx, template, _action| {
327327 let completions = template.completion.clone();
328− editor.debug_config_completions = completions;
328+ cx.editor.debug_config_completions = completions;
329329 // TODO: need some way to manipulate the compositor to push a new prompt here
330330 },
331331 ))); // TODO: wrap in popup with fixed size
@@ -755,8 +755,8 @@ pub fn dap_switch_stack_frame(cx: &mut Context) {
755755 let picker = FilePicker::new(
756756 frames,
757757 |frame| frame.name.clone().into(), // TODO: include thread_states in the label
758− move |editor, frame, _action| {
759− let debugger = match &mut editor.debugger {
758+ move |cx, frame, _action| {
759+ let debugger = match &mut cx.editor.debugger {
760760 Some(debugger) => debugger,
761761 None => return,
762762 };
@@ -770,7 +770,7 @@ pub fn dap_switch_stack_frame(cx: &mut Context) {
770770 .get(pos.unwrap_or(0))
771771 .cloned();
772772 if let Some(frame) = &frame {
773− jump_to_stack_frame(editor, frame);
773+ jump_to_stack_frame(cx.editor, frame);
774774 }
775775 },
776776 move |_editor, frame| {
helix-term/src/ui/mod.rs+3−3
@@ -21,7 +21,7 @@ pub use text::Text;
2121
2222use helix_core::regex::Regex;
2323use helix_core::regex::RegexBuilder;
24−use helix_view::{Document, Editor, View};
24+use helix_view::{Document, View};
2525
2626use std::path::PathBuf;
2727
@@ -151,8 +151,8 @@ pub fn file_picker(root: PathBuf) -> FilePicker<PathBuf> {
151151 .unwrap()
152152 .into()
153153 },
154− move |editor: &mut Editor, path: &PathBuf, action| {
155− editor
154+ move |cx, path: &PathBuf, action| {
155+ cx.editor
156156 .open(path.into(), action)
157157 .expect("editor.open failed");
158158 },
helix-term/src/ui/picker.rs+6−6
@@ -84,7 +84,7 @@ impl<T> FilePicker<T> {
8484 pub fn new(
8585 options: Vec<T>,
8686 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,
8888 preview_fn: impl Fn(&Editor, &T) -> Option<FileLocation> + 'static,
8989 ) -> Self {
9090 Self {
@@ -278,7 +278,7 @@ pub struct Picker<T> {
278278 render_centered: bool,
279279
280280 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)>,
282282}
283283
284284impl<T> Picker<T> {
@@ -286,7 +286,7 @@ impl<T> Picker<T> {
286286 render_centered: bool,
287287 options: Vec<T>,
288288 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,
290290 ) -> Self {
291291 let prompt = Prompt::new(
292292 "".into(),
@@ -452,7 +452,7 @@ impl<T: 'static> Component for Picker<T> {
452452 ..
453453 } => {
454454 if let Some(option) = self.selection() {
455− (self.callback_fn)(&mut cx.editor, option, Action::Replace);
455+ (self.callback_fn)(cx, option, Action::Replace);
456456 }
457457 return close_fn;
458458 }
@@ -461,7 +461,7 @@ impl<T: 'static> Component for Picker<T> {
461461 modifiers: KeyModifiers::CONTROL,
462462 } => {
463463 if let Some(option) = self.selection() {
464− (self.callback_fn)(&mut cx.editor, option, Action::HorizontalSplit);
464+ (self.callback_fn)(cx, option, Action::HorizontalSplit);
465465 }
466466 return close_fn;
467467 }
@@ -470,7 +470,7 @@ impl<T: 'static> Component for Picker<T> {
470470 modifiers: KeyModifiers::CONTROL,
471471 } => {
472472 if let Some(option) = self.selection() {
473− (self.callback_fn)(&mut cx.editor, option, Action::VerticalSplit);
473+ (self.callback_fn)(cx, option, Action::VerticalSplit);
474474 }
475475 return close_fn;
476476 }