1use crate::EditorEvent;
2
3use super::{Editor, EditorElement, EditorStyle};
4use gpui::{App, Context, Entity, Render, Window};
5use ui::{Element, IntoElement};
6use workspace::ItemHandle;
7
8// stage 1: render two side-by-side editors with the correct scrolling behavior
9// stage 2: add alignment map to insert blank lines
10
11/// An editor that can be rendered with a split diff layout.
12///
13/// When [secondary] is `None`, it is rendered with an inline diff style.
14pub struct SplittableEditor {
15 primary: Entity<Editor>,
16 secondary: Option<Entity<Editor>>,
17}
18
19impl SplittableEditor {
20 fn subscribe(&mut self, window: &mut Window, cx: &mut Context<Self>) {
21 cx.subscribe_in(
22 &self.primary,
23 window,
24 |this, editor, event: &EditorEvent, window, cx| {},
25 )
26 .detach();
27 }
28
29 fn sync_state(&mut self, cx: &mut App) {}
30}
31
32impl SplittableEditor {}
33
34struct SplitEditorElement {
35 primary: Entity<Editor>,
36 secondary: Entity<Editor>,
37 style: EditorStyle,
38}
39
40struct SplitEditorElementLayout {}
41
42impl Element for SplitEditorElement {
43 type RequestLayoutState = ();
44
45 type PrepaintState = SplitEditorElementLayout;
46
47 fn id(&self) -> Option<ui::ElementId> {
48 todo!()
49 }
50
51 fn source_location(&self) -> Option<&'static std::panic::Location<'static>> {
52 todo!()
53 }
54
55 fn request_layout(
56 &mut self,
57 id: Option<&gpui::GlobalElementId>,
58 inspector_id: Option<&gpui::InspectorElementId>,
59 window: &mut ui::Window,
60 cx: &mut ui::App,
61 ) -> (gpui::LayoutId, Self::RequestLayoutState) {
62 }
63
64 fn prepaint(
65 &mut self,
66 id: Option<&gpui::GlobalElementId>,
67 inspector_id: Option<&gpui::InspectorElementId>,
68 bounds: gpui::Bounds<ui::Pixels>,
69 request_layout: &mut Self::RequestLayoutState,
70 window: &mut ui::Window,
71 cx: &mut ui::App,
72 ) -> Self::PrepaintState {
73 todo!()
74 }
75
76 fn paint(
77 &mut self,
78 id: Option<&gpui::GlobalElementId>,
79 inspector_id: Option<&gpui::InspectorElementId>,
80 bounds: gpui::Bounds<ui::Pixels>,
81 request_layout: &mut Self::RequestLayoutState,
82 prepaint: &mut Self::PrepaintState,
83 window: &mut ui::Window,
84 cx: &mut ui::App,
85 ) {
86 todo!()
87 }
88}
89
90impl Render for SplittableEditor {
91 fn render(
92 &mut self,
93 window: &mut ui::Window,
94 cx: &mut ui::Context<Self>,
95 ) -> impl ui::IntoElement {
96 enum SplittableEditorElement {
97 Single(EditorElement),
98 Split(SplitEditorElement),
99 }
100
101 impl Element for SplittableEditorElement {}
102 impl IntoElement for SplittableEditorElement {
103 type Element = Self;
104
105 fn into_element(self) -> Self::Element {
106 self
107 }
108 }
109
110 let style;
111
112 if let Some(secondary) = self.secondary.clone() {
113 SplittableEditorElement::Split(SplitEditorElement {
114 primary: self.primary.clone(),
115 secondary,
116 style,
117 })
118 } else {
119 SplittableEditorElement::Single(EditorElement::new(&self.primary.clone(), style))
120 }
121 }
122}
123
124impl IntoElement for SplitEditorElement {
125 type Element = Self;
126
127 fn into_element(self) -> Self::Element {
128 self
129 }
130}