refactor: remove unneeded fields on Editor

pull/12902/head
Nik Revenco 2025-04-04 08:42:36 +01:00
parent 7b89fb4699
commit a69ca67e88
4 changed files with 15 additions and 36 deletions

View File

@ -354,16 +354,13 @@ fn create_file_operation_prompt<F>(
) where
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 call: Callback = Callback::EditorCompositor(Box::new(move |editor, compositor| {
let mut prompt = Prompt::new(
editor
.file_explorer_selected_path
.as_ref()
.map(|p| prompt(p))
.unwrap_or_default()
.into(),
// to be able to move selected_path
let path = selected_path.clone();
let prompt = Prompt::new(
prompt(&path).into(),
None,
crate::ui::completers::none,
move |cx, input: &str, event: PromptEvent| {
@ -371,24 +368,14 @@ fn create_file_operation_prompt<F>(
return;
};
let path = cx.editor.file_explorer_selected_path.clone();
if let Some(path) = path {
match file_op(cx, &path, input.to_owned()) {
Some(Ok(msg)) => cx.editor.set_status(msg),
Some(Err(msg)) => cx.editor.set_error(msg),
None => cx.editor.clear_status(),
};
} else {
cx.editor
.set_error("Unable to determine path of selected file")
}
},
);
if let Some(path_editing) = &editor.file_explorer_selected_path {
prompt.set_line_no_recalculate(prefill(path_editing));
}
)
.with_line(prefill(&selected_path), editor);
compositor.push(Box::new(prompt));
}));

View File

@ -522,7 +522,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
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)) =
(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))
};
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);
}

View File

@ -122,13 +122,6 @@ impl Prompt {
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(
mut self,
language: &'static str,

View File

@ -1101,7 +1101,6 @@ pub struct Editor {
pub mouse_down_range: Option<Range>,
pub cursor_cache: CursorCache,
pub file_explorer_selected_path: Option<PathBuf>,
}
pub type Motion = Box<dyn Fn(&mut Editor)>;
@ -1224,7 +1223,6 @@ impl Editor {
handlers,
mouse_down_range: None,
cursor_cache: CursorCache::default(),
file_explorer_selected_path: None,
}
}