mirror of https://github.com/helix-editor/helix
Merge 0a10d33eb5
into 205e7ece70
commit
f1ad88b3c4
|
@ -104,6 +104,10 @@ fn open(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow:
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open_impl(cx, args, Action::Replace)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn open_impl(cx: &mut compositor::Context, args: Args, action: Action) -> anyhow::Result<()> {
|
||||||
for arg in args {
|
for arg in args {
|
||||||
let (path, pos) = crate::args::parse_file(&arg);
|
let (path, pos) = crate::args::parse_file(&arg);
|
||||||
let path = helix_stdx::path::expand_tilde(path);
|
let path = helix_stdx::path::expand_tilde(path);
|
||||||
|
@ -113,7 +117,8 @@ fn open(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow:
|
||||||
let callback = async move {
|
let callback = async move {
|
||||||
let call: job::Callback = job::Callback::EditorCompositor(Box::new(
|
let call: job::Callback = job::Callback::EditorCompositor(Box::new(
|
||||||
move |editor: &mut Editor, compositor: &mut Compositor| {
|
move |editor: &mut Editor, compositor: &mut Compositor| {
|
||||||
let picker = ui::file_picker(editor, path.into_owned());
|
let picker =
|
||||||
|
ui::file_picker(editor, path.into_owned()).with_default_action(action);
|
||||||
compositor.push(Box::new(overlaid(picker)));
|
compositor.push(Box::new(overlaid(picker)));
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
@ -122,7 +127,7 @@ fn open(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow:
|
||||||
cx.jobs.callback(callback);
|
cx.jobs.callback(callback);
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, just open the file
|
// Otherwise, just open the file
|
||||||
let _ = cx.editor.open(&path, Action::Replace)?;
|
let _ = cx.editor.open(&path, action)?;
|
||||||
let (view, doc) = current!(cx.editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
let pos = Selection::point(pos_at_coords(doc.text().slice(..), pos, true));
|
let pos = Selection::point(pos_at_coords(doc.text().slice(..), pos, true));
|
||||||
doc.set_selection(view.id, pos);
|
doc.set_selection(view.id, pos);
|
||||||
|
@ -1745,10 +1750,7 @@ fn vsplit(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyho
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
split(cx.editor, Action::VerticalSplit);
|
split(cx.editor, Action::VerticalSplit);
|
||||||
} else {
|
} else {
|
||||||
for arg in args {
|
open_impl(cx, args, Action::VerticalSplit)?;
|
||||||
cx.editor
|
|
||||||
.open(&PathBuf::from(arg.as_ref()), Action::VerticalSplit)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1762,10 +1764,7 @@ fn hsplit(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyho
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
split(cx.editor, Action::HorizontalSplit);
|
split(cx.editor, Action::HorizontalSplit);
|
||||||
} else {
|
} else {
|
||||||
for arg in args {
|
open_impl(cx, args, Action::HorizontalSplit)?;
|
||||||
cx.editor
|
|
||||||
.open(&PathBuf::from(arg.as_ref()), Action::HorizontalSplit)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -258,6 +258,7 @@ pub struct Picker<T: 'static + Send + Sync, D: 'static> {
|
||||||
widths: Vec<Constraint>,
|
widths: Vec<Constraint>,
|
||||||
|
|
||||||
callback_fn: PickerCallback<T>,
|
callback_fn: PickerCallback<T>,
|
||||||
|
default_action: Action,
|
||||||
|
|
||||||
pub truncate_start: bool,
|
pub truncate_start: bool,
|
||||||
/// Caches paths to documents
|
/// Caches paths to documents
|
||||||
|
@ -382,6 +383,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
|
||||||
truncate_start: true,
|
truncate_start: true,
|
||||||
show_preview: true,
|
show_preview: true,
|
||||||
callback_fn: Box::new(callback_fn),
|
callback_fn: Box::new(callback_fn),
|
||||||
|
default_action: Action::Replace,
|
||||||
completion_height: 0,
|
completion_height: 0,
|
||||||
widths,
|
widths,
|
||||||
preview_cache: HashMap::new(),
|
preview_cache: HashMap::new(),
|
||||||
|
@ -440,6 +442,11 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_default_action(mut self, action: Action) -> Self {
|
||||||
|
self.default_action = action;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Move the cursor by a number of lines, either down (`Forward`) or up (`Backward`)
|
/// Move the cursor by a number of lines, either down (`Forward`) or up (`Backward`)
|
||||||
pub fn move_by(&mut self, amount: u32, direction: Direction) {
|
pub fn move_by(&mut self, amount: u32, direction: Direction) {
|
||||||
let len = self.matcher.snapshot().matched_item_count();
|
let len = self.matcher.snapshot().matched_item_count();
|
||||||
|
@ -1071,7 +1078,7 @@ impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I,
|
||||||
key!(Esc) | ctrl!('c') => return close_fn(self),
|
key!(Esc) | ctrl!('c') => return close_fn(self),
|
||||||
alt!(Enter) => {
|
alt!(Enter) => {
|
||||||
if let Some(option) = self.selection() {
|
if let Some(option) = self.selection() {
|
||||||
(self.callback_fn)(ctx, option, Action::Replace);
|
(self.callback_fn)(ctx, option, self.default_action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
key!(Enter) => {
|
key!(Enter) => {
|
||||||
|
@ -1095,7 +1102,7 @@ impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I,
|
||||||
self.handle_prompt_change(true);
|
self.handle_prompt_change(true);
|
||||||
} else {
|
} else {
|
||||||
if let Some(option) = self.selection() {
|
if let Some(option) = self.selection() {
|
||||||
(self.callback_fn)(ctx, option, Action::Replace);
|
(self.callback_fn)(ctx, option, self.default_action);
|
||||||
}
|
}
|
||||||
if let Some(history_register) = self.prompt.history_register() {
|
if let Some(history_register) = self.prompt.history_register() {
|
||||||
if let Err(err) = ctx
|
if let Err(err) = ctx
|
||||||
|
|
Loading…
Reference in New Issue