on master help sign in
Wire up opening in splits via pickers.
5c2d2fdBlaž Hrastnik
helix-term/src/commands.rs+5−5
@@ -864,7 +864,7 @@ pub fn buffer_picker(cx: &mut Context) {
864 None => "[NEW]".into(),
864 None => "[NEW]".into(),
865 }
865 }
866 },
866 },
867− |editor: &mut Editor, (_, path): &(DocumentId, Option<PathBuf>)| match path {
867+ |editor: &mut Editor, (_, path): &(DocumentId, Option<PathBuf>), _action| match path {
868 Some(path) => {
868 Some(path) => {
869 use helix_view::editor::Action;
869 use helix_view::editor::Action;
870 editor
870 editor
@@ -1082,10 +1082,10 @@ fn _goto(cx: &mut Context, locations: Vec<lsp::Location>) {
1082 let line = item.range.start.line;
1082 let line = item.range.start.line;
1083 format!("{}:{}", file, line).into()
1083 format!("{}:{}", file, line).into()
1084 },
1084 },
1085− move |editor: &mut Editor, item| {
1085+ move |editor: &mut Editor, item, action| {
1086+ let id = editor
1086− editor.open(PathBuf::from(item.uri.path()), Action::Replace);
1087+ .open(PathBuf::from(item.uri.path()), action)
1087− // TODO: issues with doc already being broo
1088+ .expect("editor.open failed");
1088− let id = editor.view().doc;
1089 let doc = &mut editor.documents[id];
1089 let doc = &mut editor.documents[id];
1090 let definition_pos = item.range.start;
1090 let definition_pos = item.range.start;
1091 let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text(), definition_pos);
1091 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> {
103 // format_fn
103 // format_fn
104 path.strip_prefix("./").unwrap().to_str().unwrap().into()
104 path.strip_prefix("./").unwrap().to_str().unwrap().into()
105 },
105 },
106− move |editor: &mut Editor, path: &PathBuf| {
106+ move |editor: &mut Editor, path: &PathBuf, action| {
107− use helix_view::editor::Action;
108 let document_id = editor
107 let document_id = editor
109− .open(path.into(), Action::Replace)
108+ .open(path.into(), action)
110 .expect("editor.open failed");
109 .expect("editor.open failed");
111 },
110 },
112 )
111 )
helix-term/src/ui/picker.rs+22−10
@@ -14,6 +14,7 @@ use std::borrow::Cow;
14
14
15use crate::ui::{Prompt, PromptEvent};
15use crate::ui::{Prompt, PromptEvent};
16use helix_core::Position;
16use helix_core::Position;
17+use helix_view::editor::Action;
17use helix_view::Editor;
18use helix_view::Editor;
18
19
19pub struct Picker<T> {
20pub struct Picker<T> {
@@ -28,14 +29,14 @@ pub struct Picker<T> {
28 prompt: Prompt,
29 prompt: Prompt,
29
30
30 format_fn: Box<dyn Fn(&T) -> Cow<str>>,
31 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)>,
32}
33}
33
34
34impl<T> Picker<T> {
35impl<T> Picker<T> {
35 pub fn new(
36 pub fn new(
36 options: Vec<T>,
37 options: Vec<T>,
37 format_fn: impl Fn(&T) -> Cow<str> + 'static,
38 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,
39 ) -> Self {
40 ) -> Self {
40 let prompt = Prompt::new(
41 let prompt = Prompt::new(
41 "".to_string(),
42 "".to_string(),
@@ -133,13 +134,6 @@ impl<T> Component for Picker<T> {
133 )));
134 )));
134
135
135 match key_event {
136 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− // }
143 KeyEvent {
137 KeyEvent {
144 code: KeyCode::Up, ..
138 code: KeyCode::Up, ..
145 }
139 }
@@ -165,7 +159,25 @@ impl<T> Component for Picker<T> {
165 ..
159 ..
166 } => {
160 } => {
167 if let Some(option) = self.selection() {
161 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);
169 }
181 }
170 return close_fn;
182 return close_fn;
171 }
183 }