on master help sign in
Wire up opening in splits via pickers.
commit5c2d2fda213164fe2cba005f28cee263486587ed authorBlaž Hrastnik <blaz@mxxn.io> dateMon 29 Mar 2021, 15:21 (6 years ago) parentaefafc2
3 files changed+29−18
helix-term/src/commands.rs+5−5 helix-term/src/ui/mod.rs+2−3 helix-term/src/ui/picker.rs+22−10
helix-term/src/commands.rs+5−5
@@ -864,7 +864,7 @@ pub fn buffer_picker(cx: &mut Context) {
864864 None => "[NEW]".into(),
865865 }
866866 },
867− |editor: &mut Editor, (_, path): &(DocumentId, Option<PathBuf>)| match path {
867+ |editor: &mut Editor, (_, path): &(DocumentId, Option<PathBuf>), _action| match path {
868868 Some(path) => {
869869 use helix_view::editor::Action;
870870 editor
@@ -1082,10 +1082,10 @@ fn _goto(cx: &mut Context, locations: Vec<lsp::Location>) {
10821082 let line = item.range.start.line;
10831083 format!("{}:{}", file, line).into()
10841084 },
1085− move |editor: &mut Editor, item| {
1086− editor.open(PathBuf::from(item.uri.path()), Action::Replace);
1087− // TODO: issues with doc already being broo
1088− let id = editor.view().doc;
1085+ move |editor: &mut Editor, item, action| {
1086+ let id = editor
1087+ .open(PathBuf::from(item.uri.path()), action)
1088+ .expect("editor.open failed");
10891089 let doc = &mut editor.documents[id];
10901090 let definition_pos = item.range.start;
10911091 let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text(), definition_pos);
helix-term/src/ui/mod.rs+2−3
@@ -103,10 +103,9 @@ pub fn file_picker(root: &str) -> Picker<PathBuf> {
103103 // format_fn
104104 path.strip_prefix("./").unwrap().to_str().unwrap().into()
105105 },
106− move |editor: &mut Editor, path: &PathBuf| {
107− use helix_view::editor::Action;
106+ move |editor: &mut Editor, path: &PathBuf, action| {
108107 let document_id = editor
109− .open(path.into(), Action::Replace)
108+ .open(path.into(), action)
110109 .expect("editor.open failed");
111110 },
112111 )
helix-term/src/ui/picker.rs+22−10
@@ -14,6 +14,7 @@ use std::borrow::Cow;
1414
1515use crate::ui::{Prompt, PromptEvent};
1616use helix_core::Position;
17+use helix_view::editor::Action;
1718use helix_view::Editor;
1819
1920pub struct Picker<T> {
@@ -28,14 +29,14 @@ pub struct Picker<T> {
2829 prompt: Prompt,
2930
3031 format_fn: Box<dyn Fn(&T) -> Cow<str>>,
31− callback_fn: Box<dyn Fn(&mut Editor, &T)>,
32+ callback_fn: Box<dyn Fn(&mut Editor, &T, Action)>,
3233}
3334
3435impl<T> Picker<T> {
3536 pub fn new(
3637 options: Vec<T>,
3738 format_fn: impl Fn(&T) -> Cow<str> + 'static,
38− callback_fn: impl Fn(&mut Editor, &T) + 'static,
39+ callback_fn: impl Fn(&mut Editor, &T, Action) + 'static,
3940 ) -> Self {
4041 let prompt = Prompt::new(
4142 "".to_string(),
@@ -133,13 +134,6 @@ impl<T> Component for Picker<T> {
133134 )));
134135
135136 match key_event {
136− // KeyEvent {
137− // code: KeyCode::Char(c),
138− // modifiers: KeyModifiers::NONE,
139− // } => {
140− // self.insert_char(c);
141− // (self.callback_fn)(cx.editor, &self.line, PromptEvent::Update);
142− // }
143137 KeyEvent {
144138 code: KeyCode::Up, ..
145139 }
@@ -165,7 +159,25 @@ impl<T> Component for Picker<T> {
165159 ..
166160 } => {
167161 if let Some(option) = self.selection() {
168− (self.callback_fn)(&mut cx.editor, option);
162+ (self.callback_fn)(&mut cx.editor, option, Action::Replace);
163+ }
164+ return close_fn;
165+ }
166+ KeyEvent {
167+ code: KeyCode::Char('x'),
168+ modifiers: KeyModifiers::CONTROL,
169+ } => {
170+ if let Some(option) = self.selection() {
171+ (self.callback_fn)(&mut cx.editor, option, Action::VerticalSplit);
172+ }
173+ return close_fn;
174+ }
175+ KeyEvent {
176+ code: KeyCode::Char('v'),
177+ modifiers: KeyModifiers::CONTROL,
178+ } => {
179+ if let Some(option) = self.selection() {
180+ (self.callback_fn)(&mut cx.editor, option, Action::HorizontalSplit);
169181 }
170182 return close_fn;
171183 }