Wire up opening in splits via pickers.

pull/11/head
Blaž Hrastnik 3 years ago
parent aefafc25cd
commit 5c2d2fda21

@ -864,7 +864,7 @@ pub fn buffer_picker(cx: &mut Context) {
None => "[NEW]".into(),
}
},
|editor: &mut Editor, (_, path): &(DocumentId, Option<PathBuf>)| match path {
|editor: &mut Editor, (_, path): &(DocumentId, Option<PathBuf>), _action| match path {
Some(path) => {
use helix_view::editor::Action;
editor
@ -1082,10 +1082,10 @@ fn _goto(cx: &mut Context, locations: Vec<lsp::Location>) {
let line = item.range.start.line;
format!("{}:{}", file, line).into()
},
move |editor: &mut Editor, item| {
editor.open(PathBuf::from(item.uri.path()), Action::Replace);
// TODO: issues with doc already being broo
let id = editor.view().doc;
move |editor: &mut Editor, item, action| {
let id = editor
.open(PathBuf::from(item.uri.path()), action)
.expect("editor.open failed");
let doc = &mut editor.documents[id];
let definition_pos = item.range.start;
let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text(), definition_pos);

@ -103,10 +103,9 @@ pub fn file_picker(root: &str) -> Picker<PathBuf> {
// format_fn
path.strip_prefix("./").unwrap().to_str().unwrap().into()
},
move |editor: &mut Editor, path: &PathBuf| {
use helix_view::editor::Action;
move |editor: &mut Editor, path: &PathBuf, action| {
let document_id = editor
.open(path.into(), Action::Replace)
.open(path.into(), action)
.expect("editor.open failed");
},
)

@ -14,6 +14,7 @@ use std::borrow::Cow;
use crate::ui::{Prompt, PromptEvent};
use helix_core::Position;
use helix_view::editor::Action;
use helix_view::Editor;
pub struct Picker<T> {
@ -28,14 +29,14 @@ pub struct Picker<T> {
prompt: Prompt,
format_fn: Box<dyn Fn(&T) -> Cow<str>>,
callback_fn: Box<dyn Fn(&mut Editor, &T)>,
callback_fn: Box<dyn Fn(&mut Editor, &T, Action)>,
}
impl<T> Picker<T> {
pub fn new(
options: Vec<T>,
format_fn: impl Fn(&T) -> Cow<str> + 'static,
callback_fn: impl Fn(&mut Editor, &T) + 'static,
callback_fn: impl Fn(&mut Editor, &T, Action) + 'static,
) -> Self {
let prompt = Prompt::new(
"".to_string(),
@ -133,13 +134,6 @@ impl<T> Component for Picker<T> {
)));
match key_event {
// KeyEvent {
// code: KeyCode::Char(c),
// modifiers: KeyModifiers::NONE,
// } => {
// self.insert_char(c);
// (self.callback_fn)(cx.editor, &self.line, PromptEvent::Update);
// }
KeyEvent {
code: KeyCode::Up, ..
}
@ -165,7 +159,25 @@ impl<T> Component for Picker<T> {
..
} => {
if let Some(option) = self.selection() {
(self.callback_fn)(&mut cx.editor, option);
(self.callback_fn)(&mut cx.editor, option, Action::Replace);
}
return close_fn;
}
KeyEvent {
code: KeyCode::Char('x'),
modifiers: KeyModifiers::CONTROL,
} => {
if let Some(option) = self.selection() {
(self.callback_fn)(&mut cx.editor, option, Action::VerticalSplit);
}
return close_fn;
}
KeyEvent {
code: KeyCode::Char('v'),
modifiers: KeyModifiers::CONTROL,
} => {
if let Some(option) = self.selection() {
(self.callback_fn)(&mut cx.editor, option, Action::HorizontalSplit);
}
return close_fn;
}

Loading…
Cancel
Save