aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/compositor.rs
diff options
context:
space:
mode:
authorJJ2023-11-01 00:37:26 +0000
committerJJ2023-11-01 04:08:32 +0000
commit5c371208692df2727d02a37646b7829f011680a8 (patch)
tree5f6cce3547e367942746ceb6499018628297a595 /helix-term/src/compositor.rs
parentf6021dd0cdd8cf6795f024e396241cb0af2ca368 (diff)
Add file explorer and tree helper
ref: https://github.com/helix-editor/helix/issues/200 ref: https://github.com/helix-editor/helix/pull/2377 ref: https://github.com/helix-editor/helix/pull/5566 ref: https://github.com/helix-editor/helix/pull/5768 Co-authored-by: cossonleo <cossonleo@foxmail.com> Co-authored-by: wongjiahau <hou32hou@gmail.com>
Diffstat (limited to 'helix-term/src/compositor.rs')
-rw-r--r--helix-term/src/compositor.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs
index 3dcb5f2b..6a357401 100644
--- a/helix-term/src/compositor.rs
+++ b/helix-term/src/compositor.rs
@@ -35,6 +35,50 @@ impl<'a> Context<'a> {
tokio::task::block_in_place(|| helix_lsp::block_on(self.editor.flush_writes()))?;
Ok(())
}
+
+ /// Purpose: to test `handle_event` without escalating the test case to integration test
+ /// Usage:
+ /// ```
+ /// let mut editor = Context::dummy_editor();
+ /// let mut jobs = Context::dummy_jobs();
+ /// let mut cx = Context::dummy(&mut jobs, &mut editor);
+ /// ```
+ #[cfg(test)]
+ pub fn dummy(jobs: &'a mut Jobs, editor: &'a mut helix_view::Editor) -> Context<'a> {
+ Context {
+ jobs,
+ scroll: None,
+ editor,
+ }
+ }
+
+ #[cfg(test)]
+ pub fn dummy_jobs() -> Jobs {
+ Jobs::new()
+ }
+
+ #[cfg(test)]
+ pub fn dummy_editor() -> Editor {
+ use crate::config::Config;
+ use arc_swap::{access::Map, ArcSwap};
+ use helix_core::syntax::{self, Configuration};
+ use helix_view::theme;
+ use std::{collections::HashMap, sync::Arc};
+
+ let config = Arc::new(ArcSwap::from_pointee(Config::default()));
+ Editor::new(
+ Rect::new(0, 0, 60, 120),
+ Arc::new(theme::Loader::new(&[])),
+ Arc::new(syntax::Loader::new(Configuration {
+ language: vec![],
+ language_server: HashMap::new(),
+ })),
+ Arc::new(Arc::new(Map::new(
+ Arc::clone(&config),
+ |config: &Config| &config.editor,
+ ))),
+ )
+ }
}
pub trait Component: Any + AnyComponent {
@@ -73,6 +117,21 @@ pub trait Component: Any + AnyComponent {
fn id(&self) -> Option<&'static str> {
None
}
+
+ #[cfg(test)]
+ /// Utility method for testing `handle_event` without using integration test.
+ /// Especially useful for testing helper components such as `Prompt`, `TreeView` etc
+ fn handle_events(&mut self, events: &str) -> anyhow::Result<()> {
+ use helix_view::input::parse_macro;
+
+ let mut editor = Context::dummy_editor();
+ let mut jobs = Context::dummy_jobs();
+ let mut cx = Context::dummy(&mut jobs, &mut editor);
+ for event in parse_macro(events)? {
+ self.handle_event(&Event::Key(event), &mut cx);
+ }
+ Ok(())
+ }
}
pub struct Compositor {