Implement vertical split calculations.
This commit is contained in:
parent
d4b85ce18d
commit
5e73f83efa
5 changed files with 39 additions and 11 deletions
3
TODO.md
3
TODO.md
|
@ -10,8 +10,9 @@
|
|||
1
|
||||
- [ ] selection mode
|
||||
- [x] % for whole doc selection
|
||||
- [ ] vertical splits
|
||||
- [x] vertical splits
|
||||
- [ ] input counts (30j)
|
||||
- [ ] respect view fullscreen flag
|
||||
- [ ] retain horiz when moving vertically
|
||||
- [ ] update lsp on redo/undo
|
||||
- [ ] Implement marks (superset of Selection/Range)
|
||||
|
|
|
@ -42,8 +42,8 @@ impl EditorView {
|
|||
viewport.x + OFFSET,
|
||||
viewport.y,
|
||||
viewport.width - OFFSET,
|
||||
viewport.height - 2,
|
||||
); // - 2 for statusline and prompt
|
||||
viewport.height - 1,
|
||||
); // - 1 for statusline
|
||||
self.render_buffer(view, area, surface, theme, is_focused);
|
||||
|
||||
// clear with background color
|
||||
|
@ -52,7 +52,7 @@ impl EditorView {
|
|||
|
||||
let area = Rect::new(
|
||||
viewport.x,
|
||||
viewport.y + viewport.height - 2,
|
||||
viewport.y + viewport.height - 1,
|
||||
viewport.width,
|
||||
1,
|
||||
);
|
||||
|
@ -301,9 +301,8 @@ impl Component for EditorView {
|
|||
fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
|
||||
match event {
|
||||
Event::Resize(width, height) => {
|
||||
// TODO: simplistic ensure cursor in view for now
|
||||
// TODO: loop over views
|
||||
cx.editor.tree.resize(Rect::new(0, 0, width, height));
|
||||
// HAXX: offset the render area height by 1 to account for prompt/commandline
|
||||
cx.editor.tree.resize(Rect::new(0, 0, width, height - 1));
|
||||
// TODO: restore view.ensure_cursor_in_view();
|
||||
EventResult::Consumed(None)
|
||||
}
|
||||
|
@ -353,10 +352,11 @@ impl Component for EditorView {
|
|||
}
|
||||
}
|
||||
|
||||
fn render(&self, area: Rect, surface: &mut Surface, cx: &mut Context) {
|
||||
fn render(&self, mut area: Rect, surface: &mut Surface, cx: &mut Context) {
|
||||
// SAFETY: we cheat around the view_mut() borrow because it doesn't allow us to also borrow
|
||||
// theme. Theme is immutable mutating view won't disrupt theme_ref.
|
||||
let theme_ref = unsafe { &*(&cx.editor.theme as *const Theme) };
|
||||
|
||||
for (view, is_focused) in cx.editor.tree.views() {
|
||||
// TODO: use parent area
|
||||
self.render_view(view, view.area, surface, theme_ref, is_focused);
|
||||
|
|
|
@ -15,10 +15,13 @@ pub struct Editor {
|
|||
}
|
||||
|
||||
impl Editor {
|
||||
pub fn new(area: tui::layout::Rect) -> Self {
|
||||
pub fn new(mut area: tui::layout::Rect) -> Self {
|
||||
let theme = Theme::default();
|
||||
let language_servers = helix_lsp::Registry::new();
|
||||
|
||||
// HAXX: offset the render area height by 1 to account for prompt/commandline
|
||||
area.height -= 1;
|
||||
|
||||
Self {
|
||||
tree: Tree::new(area),
|
||||
should_close: false,
|
||||
|
|
|
@ -156,7 +156,31 @@ impl Tree {
|
|||
container.area = area;
|
||||
|
||||
match container.layout {
|
||||
Layout::Vertical => unimplemented!(),
|
||||
Layout::Vertical => {
|
||||
let len = container.children.len();
|
||||
|
||||
let height = area.height / len as u16;
|
||||
|
||||
let mut child_y = area.y;
|
||||
|
||||
for (i, child) in container.children.iter().enumerate() {
|
||||
let mut area = Rect::new(
|
||||
container.area.x,
|
||||
child_y,
|
||||
container.area.width,
|
||||
height,
|
||||
);
|
||||
child_y += height;
|
||||
|
||||
// last child takes the remaining width because we can get uneven
|
||||
// space from rounding
|
||||
if i == len - 1 {
|
||||
area.height = container.area.y + container.area.height - area.y;
|
||||
}
|
||||
|
||||
self.stack.push((*child, area));
|
||||
}
|
||||
}
|
||||
Layout::Horizontal => {
|
||||
let len = container.children.len();
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ impl View {
|
|||
/// Calculates the last visible line on screen
|
||||
#[inline]
|
||||
pub fn last_line(&self) -> usize {
|
||||
let viewport = Rect::new(6, 0, self.area.width, self.area.height - 2); // - 2 for statusline and prompt
|
||||
let viewport = Rect::new(6, 0, self.area.width, self.area.height - 1); // - 1 for statusline
|
||||
std::cmp::min(
|
||||
self.first_line + (viewport.height as usize),
|
||||
self.doc.text().len_lines() - 1,
|
||||
|
|
Loading…
Reference in a new issue