Skip to content

Commit

Permalink
copy layout method from syntax tree view to calculate pane height
Browse files Browse the repository at this point in the history
  • Loading branch information
kierangilliam committed Jan 29, 2024
1 parent 7186899 commit 29c1e09
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions crates/markdown_preview/src/markdown_preview_view.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use editor::{Editor, EditorEvent};
use gpui::{
AnyElement, AppContext, EventEmitter, FocusHandle, FocusableView, InteractiveElement,
IntoElement, ParentElement, Render, Styled, View, ViewContext,
canvas, AnyElement, AppContext, AvailableSpace, EventEmitter, FocusHandle, FocusableView,
InteractiveElement, IntoElement, ParentElement, Render, Styled, View, ViewContext,
};
use language::LanguageRegistry;
use std::sync::Arc;
Expand Down Expand Up @@ -140,17 +140,11 @@ impl Item for MarkdownPreviewView {

impl Render for MarkdownPreviewView {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
// TODO: This is wrong but I'm unsure how
// to make the preview scrollable without specifying
// a real height as max_h_full does not work.
let viewport_height = cx.viewport_size().height;

let mut container = v_flex()
.items_start()
.justify_start()
.key_context("MarkdownPreview")
.track_focus(&self.focus_handle)
.max_h(viewport_height)
.id("MarkdownPreview")
.overflow_scroll()
.size_full()
Expand All @@ -164,6 +158,15 @@ impl Render for MarkdownPreviewView {
container = container.child(item.mb_2());
}

container.into_any()
div().flex_1().child(
canvas(move |bounds, cx| {
container.into_any().draw(
bounds.origin,
bounds.size.map(AvailableSpace::Definite),
cx,
)
})
.size_full(),
)
}
}

0 comments on commit 29c1e09

Please sign in to comment.