Make picker take the whole context, not just editor
This commit is contained in:
parent
64bb1f7563
commit
3b8d5102ac
4 changed files with 28 additions and 30 deletions
|
@ -1458,11 +1458,11 @@ fn global_search(cx: &mut Context) {
|
||||||
relative_path.into()
|
relative_path.into()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
move |editor: &mut Editor, (line_num, path), action| {
|
move |cx, (line_num, path), action| {
|
||||||
match editor.open(path.into(), action) {
|
match cx.editor.open(path.into(), action) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
editor.set_error(format!(
|
cx.editor.set_error(format!(
|
||||||
"Failed to open file '{}': {}",
|
"Failed to open file '{}': {}",
|
||||||
path.display(),
|
path.display(),
|
||||||
e
|
e
|
||||||
|
@ -1472,7 +1472,7 @@ fn global_search(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let line_num = *line_num;
|
let line_num = *line_num;
|
||||||
let (view, doc) = current!(editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
let text = doc.text();
|
let text = doc.text();
|
||||||
let start = text.line_to_char(line_num);
|
let start = text.line_to_char(line_num);
|
||||||
let end = text.line_to_char((line_num + 1).min(text.len_lines()));
|
let end = text.line_to_char((line_num + 1).min(text.len_lines()));
|
||||||
|
@ -2717,8 +2717,8 @@ fn buffer_picker(cx: &mut Context) {
|
||||||
None => "[scratch buffer]".into(),
|
None => "[scratch buffer]".into(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
|
|cx, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
|
||||||
editor.switch(*id, Action::Replace);
|
cx.editor.switch(*id, Action::Replace);
|
||||||
},
|
},
|
||||||
|editor, (id, path)| {
|
|editor, (id, path)| {
|
||||||
let doc = &editor.documents.get(id)?;
|
let doc = &editor.documents.get(id)?;
|
||||||
|
@ -2785,9 +2785,9 @@ fn symbol_picker(cx: &mut Context) {
|
||||||
let picker = FilePicker::new(
|
let picker = FilePicker::new(
|
||||||
symbols,
|
symbols,
|
||||||
|symbol| (&symbol.name).into(),
|
|symbol| (&symbol.name).into(),
|
||||||
move |editor: &mut Editor, symbol, _action| {
|
move |cx, symbol, _action| {
|
||||||
push_jump(editor);
|
push_jump(cx.editor);
|
||||||
let (view, doc) = current!(editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
|
|
||||||
if let Some(range) =
|
if let Some(range) =
|
||||||
lsp_range_to_range(doc.text(), symbol.location.range, offset_encoding)
|
lsp_range_to_range(doc.text(), symbol.location.range, offset_encoding)
|
||||||
|
@ -2845,15 +2845,15 @@ pub fn code_action(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
lsp::CodeActionOrCommand::Command(command) => command.title.as_str().into(),
|
lsp::CodeActionOrCommand::Command(command) => command.title.as_str().into(),
|
||||||
},
|
},
|
||||||
move |editor, code_action, _action| match code_action {
|
move |cx, code_action, _action| match code_action {
|
||||||
lsp::CodeActionOrCommand::Command(command) => {
|
lsp::CodeActionOrCommand::Command(command) => {
|
||||||
log::debug!("code action command: {:?}", command);
|
log::debug!("code action command: {:?}", command);
|
||||||
editor.set_error(String::from("Handling code action command is not implemented yet, see https://github.com/helix-editor/helix/issues/183"));
|
cx.editor.set_error(String::from("Handling code action command is not implemented yet, see https://github.com/helix-editor/helix/issues/183"));
|
||||||
}
|
}
|
||||||
lsp::CodeActionOrCommand::CodeAction(code_action) => {
|
lsp::CodeActionOrCommand::CodeAction(code_action) => {
|
||||||
log::debug!("code action: {:?}", code_action);
|
log::debug!("code action: {:?}", code_action);
|
||||||
if let Some(ref workspace_edit) = code_action.edit {
|
if let Some(ref workspace_edit) = code_action.edit {
|
||||||
apply_workspace_edit(editor, offset_encoding, workspace_edit)
|
apply_workspace_edit(cx.editor, offset_encoding, workspace_edit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -3267,9 +3267,7 @@ fn goto_impl(
|
||||||
let line = location.range.start.line;
|
let line = location.range.start.line;
|
||||||
format!("{}:{}", file, line).into()
|
format!("{}:{}", file, line).into()
|
||||||
},
|
},
|
||||||
move |editor: &mut Editor, location, action| {
|
move |cx, location, action| jump_to(cx.editor, location, offset_encoding, action),
|
||||||
jump_to(editor, location, offset_encoding, action)
|
|
||||||
},
|
|
||||||
|_editor, location| {
|
|_editor, location| {
|
||||||
let path = location.uri.to_file_path().unwrap();
|
let path = location.uri.to_file_path().unwrap();
|
||||||
let line = Some((
|
let line = Some((
|
||||||
|
|
|
@ -128,7 +128,7 @@ fn thread_picker(cx: &mut Context, callback_fn: impl Fn(&mut Editor, &dap::Threa
|
||||||
)
|
)
|
||||||
.into()
|
.into()
|
||||||
},
|
},
|
||||||
move |editor, thread, _action| callback_fn(editor, thread),
|
move |cx, thread, _action| callback_fn(cx.editor, thread),
|
||||||
move |_editor, thread| {
|
move |_editor, thread| {
|
||||||
if let Some(frame) = frames.get(&thread.id).and_then(|bt| bt.get(0)) {
|
if let Some(frame) = frames.get(&thread.id).and_then(|bt| bt.get(0)) {
|
||||||
frame
|
frame
|
||||||
|
@ -323,9 +323,9 @@ pub fn dap_launch(cx: &mut Context) {
|
||||||
true,
|
true,
|
||||||
config.templates,
|
config.templates,
|
||||||
|template| template.name.as_str().into(),
|
|template| template.name.as_str().into(),
|
||||||
|editor, template, _action| {
|
|cx, template, _action| {
|
||||||
let completions = template.completion.clone();
|
let completions = template.completion.clone();
|
||||||
editor.debug_config_completions = completions;
|
cx.editor.debug_config_completions = completions;
|
||||||
// TODO: need some way to manipulate the compositor to push a new prompt here
|
// TODO: need some way to manipulate the compositor to push a new prompt here
|
||||||
},
|
},
|
||||||
))); // TODO: wrap in popup with fixed size
|
))); // TODO: wrap in popup with fixed size
|
||||||
|
@ -755,8 +755,8 @@ pub fn dap_switch_stack_frame(cx: &mut Context) {
|
||||||
let picker = FilePicker::new(
|
let picker = FilePicker::new(
|
||||||
frames,
|
frames,
|
||||||
|frame| frame.name.clone().into(), // TODO: include thread_states in the label
|
|frame| frame.name.clone().into(), // TODO: include thread_states in the label
|
||||||
move |editor, frame, _action| {
|
move |cx, frame, _action| {
|
||||||
let debugger = match &mut editor.debugger {
|
let debugger = match &mut cx.editor.debugger {
|
||||||
Some(debugger) => debugger,
|
Some(debugger) => debugger,
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
@ -770,7 +770,7 @@ pub fn dap_switch_stack_frame(cx: &mut Context) {
|
||||||
.get(pos.unwrap_or(0))
|
.get(pos.unwrap_or(0))
|
||||||
.cloned();
|
.cloned();
|
||||||
if let Some(frame) = &frame {
|
if let Some(frame) = &frame {
|
||||||
jump_to_stack_frame(editor, frame);
|
jump_to_stack_frame(cx.editor, frame);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
move |_editor, frame| {
|
move |_editor, frame| {
|
||||||
|
|
|
@ -21,7 +21,7 @@ pub use text::Text;
|
||||||
|
|
||||||
use helix_core::regex::Regex;
|
use helix_core::regex::Regex;
|
||||||
use helix_core::regex::RegexBuilder;
|
use helix_core::regex::RegexBuilder;
|
||||||
use helix_view::{Document, Editor, View};
|
use helix_view::{Document, View};
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
@ -151,8 +151,8 @@ pub fn file_picker(root: PathBuf) -> FilePicker<PathBuf> {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into()
|
.into()
|
||||||
},
|
},
|
||||||
move |editor: &mut Editor, path: &PathBuf, action| {
|
move |cx, path: &PathBuf, action| {
|
||||||
editor
|
cx.editor
|
||||||
.open(path.into(), action)
|
.open(path.into(), action)
|
||||||
.expect("editor.open failed");
|
.expect("editor.open failed");
|
||||||
},
|
},
|
||||||
|
|
|
@ -84,7 +84,7 @@ impl<T> FilePicker<T> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
options: Vec<T>,
|
options: Vec<T>,
|
||||||
format_fn: impl Fn(&T) -> Cow<str> + 'static,
|
format_fn: impl Fn(&T) -> Cow<str> + 'static,
|
||||||
callback_fn: impl Fn(&mut Editor, &T, Action) + 'static,
|
callback_fn: impl Fn(&mut Context, &T, Action) + 'static,
|
||||||
preview_fn: impl Fn(&Editor, &T) -> Option<FileLocation> + 'static,
|
preview_fn: impl Fn(&Editor, &T) -> Option<FileLocation> + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -278,7 +278,7 @@ pub struct Picker<T> {
|
||||||
render_centered: bool,
|
render_centered: bool,
|
||||||
|
|
||||||
format_fn: Box<dyn Fn(&T) -> Cow<str>>,
|
format_fn: Box<dyn Fn(&T) -> Cow<str>>,
|
||||||
callback_fn: Box<dyn Fn(&mut Editor, &T, Action)>,
|
callback_fn: Box<dyn Fn(&mut Context, &T, Action)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Picker<T> {
|
impl<T> Picker<T> {
|
||||||
|
@ -286,7 +286,7 @@ impl<T> Picker<T> {
|
||||||
render_centered: bool,
|
render_centered: bool,
|
||||||
options: Vec<T>,
|
options: Vec<T>,
|
||||||
format_fn: impl Fn(&T) -> Cow<str> + 'static,
|
format_fn: impl Fn(&T) -> Cow<str> + 'static,
|
||||||
callback_fn: impl Fn(&mut Editor, &T, Action) + 'static,
|
callback_fn: impl Fn(&mut Context, &T, Action) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let prompt = Prompt::new(
|
let prompt = Prompt::new(
|
||||||
"".into(),
|
"".into(),
|
||||||
|
@ -452,7 +452,7 @@ impl<T: 'static> Component for Picker<T> {
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
if let Some(option) = self.selection() {
|
if let Some(option) = self.selection() {
|
||||||
(self.callback_fn)(&mut cx.editor, option, Action::Replace);
|
(self.callback_fn)(cx, option, Action::Replace);
|
||||||
}
|
}
|
||||||
return close_fn;
|
return close_fn;
|
||||||
}
|
}
|
||||||
|
@ -461,7 +461,7 @@ impl<T: 'static> Component for Picker<T> {
|
||||||
modifiers: KeyModifiers::CONTROL,
|
modifiers: KeyModifiers::CONTROL,
|
||||||
} => {
|
} => {
|
||||||
if let Some(option) = self.selection() {
|
if let Some(option) = self.selection() {
|
||||||
(self.callback_fn)(&mut cx.editor, option, Action::HorizontalSplit);
|
(self.callback_fn)(cx, option, Action::HorizontalSplit);
|
||||||
}
|
}
|
||||||
return close_fn;
|
return close_fn;
|
||||||
}
|
}
|
||||||
|
@ -470,7 +470,7 @@ impl<T: 'static> Component for Picker<T> {
|
||||||
modifiers: KeyModifiers::CONTROL,
|
modifiers: KeyModifiers::CONTROL,
|
||||||
} => {
|
} => {
|
||||||
if let Some(option) = self.selection() {
|
if let Some(option) = self.selection() {
|
||||||
(self.callback_fn)(&mut cx.editor, option, Action::VerticalSplit);
|
(self.callback_fn)(cx, option, Action::VerticalSplit);
|
||||||
}
|
}
|
||||||
return close_fn;
|
return close_fn;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue