markdown/layout.rs
1//! How a document breaks its lines.
2//!
3//! Installed once at boot like the typography, and read at paint.
4
5use gpui::{App, Global};
6
7/// How a document breaks its lines.
8#[derive(Clone, Copy, Debug, PartialEq)]
9pub struct Layout {
10 /// Whether a line too long for a fence wraps, rather than scrolling
11 /// sideways inside it.
12 pub wrap_code: bool,
13}
14
15impl Layout {
16 /// How documents break lines, or [`Layout::default`] before anything is
17 /// installed. Mirrors [`theme::Theme::of`].
18 pub fn of(cx: &App) -> Self {
19 cx.try_global::<Installed>()
20 .map_or_else(Self::default, |installed| installed.0)
21 }
22}
23
24impl Default for Layout {
25 /// Wrapping, because a caret is what reads a fence here: a scroller can
26 /// hold it off the right edge, where nothing on the page brings it back.
27 fn default() -> Self {
28 Self { wrap_code: true }
29 }
30}
31
32struct Installed(Layout);
33
34impl Global for Installed {}
35
36/// `markdown::set_layout(cx, my_layout)` — call once at boot.
37pub fn set_layout(cx: &mut App, layout: Layout) {
38 cx.set_global(Installed(layout));
39}