1use std::ops::{Deref, DerefMut};
2
3use gpui::ModelHandle;
4use language::Buffer;
5use settings::Settings;
6
7use crate::MultiBuffer;
8
9use super::{build_editor, editor_test_context::EditorTestContext};
10
11pub struct EditorGitTestContext<'a> {
12 pub cx: EditorTestContext<'a>,
13 pub buffer: ModelHandle<Buffer>,
14}
15
16impl<'a> EditorGitTestContext<'a> {
17 pub async fn new(cx: &'a mut gpui::TestAppContext) -> EditorGitTestContext<'a> {
18 let (window_id, buffer, editor) = cx.update(|cx| {
19 cx.set_global(Settings::test(cx));
20 crate::init(cx);
21
22 let buffer = cx.add_model(|cx| Buffer::new(0, "", cx));
23 let multibuffer = cx.add_model(|cx| MultiBuffer::singleton(buffer.clone(), cx));
24
25 let (window_id, editor) =
26 cx.add_window(Default::default(), |cx| build_editor(multibuffer, cx));
27
28 editor.update(cx, |_, cx| cx.focus_self());
29
30 (window_id, buffer, editor)
31 });
32
33 Self {
34 cx: EditorTestContext {
35 cx,
36 window_id,
37 editor,
38 },
39 buffer,
40 }
41 }
42}
43
44impl<'a> Deref for EditorGitTestContext<'a> {
45 type Target = EditorTestContext<'a>;
46
47 fn deref(&self) -> &Self::Target {
48 &self.cx
49 }
50}
51
52impl<'a> DerefMut for EditorGitTestContext<'a> {
53 fn deref_mut(&mut self) -> &mut Self::Target {
54 &mut self.cx
55 }
56}