refactor: create Editor::set_result

pull/12902/head
Nik Revenco 2025-04-04 09:15:34 +01:00
parent 09021fdf30
commit 3aea7bba74
2 changed files with 14 additions and 8 deletions

View File

@ -55,10 +55,8 @@ where
return;
};
match overwrite(cx, picker_root.clone(), &overwrite_with) {
Some(Ok(msg)) => cx.editor.set_status(msg),
Some(Err(msg)) => cx.editor.set_error(msg),
None => (),
if let Some(result) = overwrite(cx, picker_root.clone(), &overwrite_with) {
cx.editor.set_result(result);
};
},
);
@ -99,10 +97,10 @@ fn create_file_operation_prompt<F>(
return;
};
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(),
if let Some(result) = file_op(cx, &path, input.to_owned()) {
cx.editor.set_result(result);
} else {
cx.editor.clear_status();
};
},
)

View File

@ -1299,6 +1299,14 @@ impl Editor {
self.status_msg = Some((error, Severity::Error));
}
#[inline]
pub fn set_result<T: Into<Cow<'static, str>>>(&mut self, result: Result<T, T>) {
match result {
Ok(ok) => self.set_status(ok),
Err(err) => self.set_error(err),
}
}
#[inline]
pub fn set_warning<T: Into<Cow<'static, str>>>(&mut self, warning: T) {
let warning = warning.into();