Skip to content

Commit

Permalink
Wire up opening in splits via pickers.
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Mar 29, 2021
1 parent aefafc2 commit 5c2d2fd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
10 changes: 5 additions & 5 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions helix-term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
},
)
Expand Down
32 changes: 22 additions & 10 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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(),
Expand Down Expand Up @@ -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, ..
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 5c2d2fd

Please sign in to comment.