mirror of https://github.com/helix-editor/helix
refactor: remove unneeded fields on Editor
parent
7b89fb4699
commit
a69ca67e88
|
@ -354,16 +354,13 @@ fn create_file_operation_prompt<F>(
|
||||||
) where
|
) where
|
||||||
F: Fn(&mut Context, &PathBuf, String) -> Option<Result<String, String>> + Send + 'static,
|
F: Fn(&mut Context, &PathBuf, String) -> Option<Result<String, String>> + Send + 'static,
|
||||||
{
|
{
|
||||||
cx.editor.file_explorer_selected_path = Some(path.to_path_buf());
|
let selected_path = path.to_path_buf();
|
||||||
let callback = Box::pin(async move {
|
let callback = Box::pin(async move {
|
||||||
let call: Callback = Callback::EditorCompositor(Box::new(move |editor, compositor| {
|
let call: Callback = Callback::EditorCompositor(Box::new(move |editor, compositor| {
|
||||||
let mut prompt = Prompt::new(
|
// to be able to move selected_path
|
||||||
editor
|
let path = selected_path.clone();
|
||||||
.file_explorer_selected_path
|
let prompt = Prompt::new(
|
||||||
.as_ref()
|
prompt(&path).into(),
|
||||||
.map(|p| prompt(p))
|
|
||||||
.unwrap_or_default()
|
|
||||||
.into(),
|
|
||||||
None,
|
None,
|
||||||
crate::ui::completers::none,
|
crate::ui::completers::none,
|
||||||
move |cx, input: &str, event: PromptEvent| {
|
move |cx, input: &str, event: PromptEvent| {
|
||||||
|
@ -371,24 +368,14 @@ fn create_file_operation_prompt<F>(
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let path = cx.editor.file_explorer_selected_path.clone();
|
|
||||||
|
|
||||||
if let Some(path) = path {
|
|
||||||
match file_op(cx, &path, input.to_owned()) {
|
match file_op(cx, &path, input.to_owned()) {
|
||||||
Some(Ok(msg)) => cx.editor.set_status(msg),
|
Some(Ok(msg)) => cx.editor.set_status(msg),
|
||||||
Some(Err(msg)) => cx.editor.set_error(msg),
|
Some(Err(msg)) => cx.editor.set_error(msg),
|
||||||
None => cx.editor.clear_status(),
|
None => cx.editor.clear_status(),
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
cx.editor
|
|
||||||
.set_error("Unable to determine path of selected file")
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
)
|
||||||
|
.with_line(prefill(&selected_path), editor);
|
||||||
if let Some(path_editing) = &editor.file_explorer_selected_path {
|
|
||||||
prompt.set_line_no_recalculate(prefill(path_editing));
|
|
||||||
}
|
|
||||||
|
|
||||||
compositor.push(Box::new(prompt));
|
compositor.push(Box::new(prompt));
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -522,7 +522,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
|
||||||
self.show_preview = !self.show_preview;
|
self.show_preview = !self.show_preview;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn custom_event_handler(&mut self, event: &KeyEvent, cx: &mut Context) -> EventResult {
|
fn custom_key_event_handler(&mut self, event: &KeyEvent, cx: &mut Context) -> EventResult {
|
||||||
if let (Some(callback), Some(selected)) =
|
if let (Some(callback), Some(selected)) =
|
||||||
(self.custom_key_handlers.get(event), self.selection())
|
(self.custom_key_handlers.get(event), self.selection())
|
||||||
{
|
{
|
||||||
|
@ -1070,7 +1070,8 @@ impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I,
|
||||||
EventResult::Consumed(Some(callback))
|
EventResult::Consumed(Some(callback))
|
||||||
};
|
};
|
||||||
|
|
||||||
if let EventResult::Consumed(_) = self.custom_event_handler(&key_event, ctx) {
|
// handle custom keybindings, if exist
|
||||||
|
if let EventResult::Consumed(_) = self.custom_key_event_handler(&key_event, ctx) {
|
||||||
return EventResult::Consumed(None);
|
return EventResult::Consumed(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,13 +122,6 @@ impl Prompt {
|
||||||
self.recalculate_completion(editor);
|
self.recalculate_completion(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_line_no_recalculate(&mut self, line: String) {
|
|
||||||
debug_assert!(self.completion.is_empty());
|
|
||||||
let cursor = line.len();
|
|
||||||
self.line = line;
|
|
||||||
self.cursor = cursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_language(
|
pub fn with_language(
|
||||||
mut self,
|
mut self,
|
||||||
language: &'static str,
|
language: &'static str,
|
||||||
|
|
|
@ -1101,7 +1101,6 @@ pub struct Editor {
|
||||||
|
|
||||||
pub mouse_down_range: Option<Range>,
|
pub mouse_down_range: Option<Range>,
|
||||||
pub cursor_cache: CursorCache,
|
pub cursor_cache: CursorCache,
|
||||||
pub file_explorer_selected_path: Option<PathBuf>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Motion = Box<dyn Fn(&mut Editor)>;
|
pub type Motion = Box<dyn Fn(&mut Editor)>;
|
||||||
|
@ -1224,7 +1223,6 @@ impl Editor {
|
||||||
handlers,
|
handlers,
|
||||||
mouse_down_range: None,
|
mouse_down_range: None,
|
||||||
cursor_cache: CursorCache::default(),
|
cursor_cache: CursorCache::default(),
|
||||||
file_explorer_selected_path: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue