on master help sign in
Implement vertical split calculations.
5e73f83Blaž Hrastnik
TODO.md+2−1
@@ -10,8 +10,9 @@
101
101
11- [ ] selection mode
11- [ ] selection mode
12- [x] % for whole doc selection
12- [x] % for whole doc selection
13−- [ ] vertical splits
13+- [x] vertical splits
14- [ ] input counts (30j)
14- [ ] input counts (30j)
15+- [ ] respect view fullscreen flag
15- [ ] retain horiz when moving vertically
16- [ ] retain horiz when moving vertically
16- [ ] update lsp on redo/undo
17- [ ] update lsp on redo/undo
17- [ ] Implement marks (superset of Selection/Range)
18- [ ] Implement marks (superset of Selection/Range)
helix-term/src/ui/editor.rs+7−7
@@ -42,8 +42,8 @@ impl EditorView {
42 viewport.x + OFFSET,
42 viewport.x + OFFSET,
43 viewport.y,
43 viewport.y,
44 viewport.width - OFFSET,
44 viewport.width - OFFSET,
45− viewport.height - 2,
45+ viewport.height - 1,
46− ); // - 2 for statusline and prompt
46+ ); // - 1 for statusline
47 self.render_buffer(view, area, surface, theme, is_focused);
47 self.render_buffer(view, area, surface, theme, is_focused);
48
48
49 // clear with background color
49 // clear with background color
@@ -52,7 +52,7 @@ impl EditorView {
52
52
53 let area = Rect::new(
53 let area = Rect::new(
54 viewport.x,
54 viewport.x,
55− viewport.y + viewport.height - 2,
55+ viewport.y + viewport.height - 1,
56 viewport.width,
56 viewport.width,
57 1,
57 1,
58 );
58 );
@@ -301,9 +301,8 @@ impl Component for EditorView {
301 fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
301 fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
302 match event {
302 match event {
303 Event::Resize(width, height) => {
303 Event::Resize(width, height) => {
304− // TODO: simplistic ensure cursor in view for now
304+ // HAXX: offset the render area height by 1 to account for prompt/commandline
305− // TODO: loop over views
306− cx.editor.tree.resize(Rect::new(0, 0, width, height));
305+ cx.editor.tree.resize(Rect::new(0, 0, width, height - 1));
307 // TODO: restore view.ensure_cursor_in_view();
306 // TODO: restore view.ensure_cursor_in_view();
308 EventResult::Consumed(None)
307 EventResult::Consumed(None)
309 }
308 }
@@ -353,10 +352,11 @@ impl Component for EditorView {
353 }
352 }
354 }
353 }
355
354
356− fn render(&self, area: Rect, surface: &mut Surface, cx: &mut Context) {
355+ fn render(&self, mut area: Rect, surface: &mut Surface, cx: &mut Context) {
357 // SAFETY: we cheat around the view_mut() borrow because it doesn't allow us to also borrow
356 // SAFETY: we cheat around the view_mut() borrow because it doesn't allow us to also borrow
358 // theme. Theme is immutable mutating view won't disrupt theme_ref.
357 // theme. Theme is immutable mutating view won't disrupt theme_ref.
359 let theme_ref = unsafe { &*(&cx.editor.theme as *const Theme) };
358 let theme_ref = unsafe { &*(&cx.editor.theme as *const Theme) };
359+
360 for (view, is_focused) in cx.editor.tree.views() {
360 for (view, is_focused) in cx.editor.tree.views() {
361 // TODO: use parent area
361 // TODO: use parent area
362 self.render_view(view, view.area, surface, theme_ref, is_focused);
362 self.render_view(view, view.area, surface, theme_ref, is_focused);
helix-view/src/editor.rs+4−1
@@ -15,10 +15,13 @@ pub struct Editor {
15}
15}
16
16
17impl Editor {
17impl Editor {
18− pub fn new(area: tui::layout::Rect) -> Self {
18+ pub fn new(mut area: tui::layout::Rect) -> Self {
19 let theme = Theme::default();
19 let theme = Theme::default();
20 let language_servers = helix_lsp::Registry::new();
20 let language_servers = helix_lsp::Registry::new();
21
21
22+ // HAXX: offset the render area height by 1 to account for prompt/commandline
23+ area.height -= 1;
24+
22 Self {
25 Self {
23 tree: Tree::new(area),
26 tree: Tree::new(area),
24 should_close: false,
27 should_close: false,
helix-view/src/tree.rs+25−1
@@ -156,7 +156,31 @@ impl Tree {
156 container.area = area;
156 container.area = area;
157
157
158 match container.layout {
158 match container.layout {
159− Layout::Vertical => unimplemented!(),
159+ Layout::Vertical => {
160+ let len = container.children.len();
161+
162+ let height = area.height / len as u16;
163+
164+ let mut child_y = area.y;
165+
166+ for (i, child) in container.children.iter().enumerate() {
167+ let mut area = Rect::new(
168+ container.area.x,
169+ child_y,
170+ container.area.width,
171+ height,
172+ );
173+ child_y += height;
174+
175+ // last child takes the remaining width because we can get uneven
176+ // space from rounding
177+ if i == len - 1 {
178+ area.height = container.area.y + container.area.height - area.y;
179+ }
180+
181+ self.stack.push((*child, area));
182+ }
183+ }
160 Layout::Horizontal => {
184 Layout::Horizontal => {
161 let len = container.children.len();
185 let len = container.children.len();
162
186
helix-view/src/view.rs+1−1
@@ -51,7 +51,7 @@ impl View {
51 /// Calculates the last visible line on screen
51 /// Calculates the last visible line on screen
52 #[inline]
52 #[inline]
53 pub fn last_line(&self) -> usize {
53 pub fn last_line(&self) -> usize {
54− let viewport = Rect::new(6, 0, self.area.width, self.area.height - 2); // - 2 for statusline and prompt
54+ let viewport = Rect::new(6, 0, self.area.width, self.area.height - 1); // - 1 for statusline
55 std::cmp::min(
55 std::cmp::min(
56 self.first_line + (viewport.height as usize),
56 self.first_line + (viewport.height as usize),
57 self.doc.text().len_lines() - 1,
57 self.doc.text().len_lines() - 1,