aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-29 06:21:48 +0000
committerBlaž Hrastnik2021-03-29 06:21:48 +0000
commit5c2d2fda213164fe2cba005f28cee263486587ed (patch)
tree5f064949d7ff87c00580a8f20707811d52c8c70b /helix-term/src/ui
parentaefafc25cd235183261efa2d59265855e0e992e1 (diff)
Wire up opening in splits via pickers.
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r--helix-term/src/ui/mod.rs5
-rw-r--r--helix-term/src/ui/picker.rs32
2 files changed, 24 insertions, 13 deletions
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index 2d282867..8cb82fcb 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -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");
},
)
diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs
index 853164c5..6ac35fba 100644
--- a/helix-term/src/ui/picker.rs
+++ b/helix-term/src/ui/picker.rs
@@ -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;
}