logiguard fork v3: full patch set on verified 8c74db0 tree
Includes prior-session patches (carry forward so the app compiles): - crates/gpui/build.rs: cross-compile manifest fix - crates/gpui/src/platform.rs: PlatformWindow::activate_with_token trait method - crates/gpui/src/window.rs: Window::activate_with_token public API - crates/gpui_linux/src/linux/wayland/window.rs: WaylandWindow::activate_with_token + activate() keyboard-serial fix Plus the focus-serial fix: - serial.rs: SerialKind::KeyboardEnter - client.rs: store wl_keyboard.enter serial; latest_serial_of() Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
121
crates/markdown/examples/markdown.rs
Normal file
121
crates/markdown/examples/markdown.rs
Normal file
@@ -0,0 +1,121 @@
|
||||
use assets::Assets;
|
||||
use gpui::{Entity, KeyBinding, StyleRefinement, WindowOptions, prelude::*, rgb};
|
||||
use language::LanguageRegistry;
|
||||
use markdown::{Markdown, MarkdownElement, MarkdownStyle};
|
||||
use node_runtime::NodeRuntime;
|
||||
use settings::SettingsStore;
|
||||
use std::sync::Arc;
|
||||
use theme::LoadThemes;
|
||||
use ui::prelude::*;
|
||||
use ui::{App, Window, div};
|
||||
|
||||
const MARKDOWN_EXAMPLE: &str = r#"
|
||||
# Markdown Example Document
|
||||
|
||||
## Headings
|
||||
Headings are created by adding one or more `#` symbols before your heading text. The number of `#` you use will determine the size of the heading.
|
||||
|
||||
```
|
||||
function a(b: T) {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
Remember, markdown processors may have slight differences and extensions, so always refer to the specific documentation or guides relevant to your platform or editor for the best practices and additional features.
|
||||
|
||||
## Images
|
||||
|
||||
 item one
|
||||
|
||||
 item two
|
||||
|
||||
 item three
|
||||
|
||||
"#;
|
||||
|
||||
pub fn main() {
|
||||
env_logger::init();
|
||||
gpui_platform::application().with_assets(Assets).run(|cx| {
|
||||
let store = SettingsStore::test(cx);
|
||||
cx.set_global(store);
|
||||
cx.bind_keys([KeyBinding::new("cmd-c", markdown::Copy, None)]);
|
||||
|
||||
let node_runtime = NodeRuntime::unavailable();
|
||||
theme_settings::init(LoadThemes::JustBase, cx);
|
||||
|
||||
let fs = fs::FakeFs::new(cx.background_executor().clone());
|
||||
let language_registry = LanguageRegistry::new(cx.background_executor().clone());
|
||||
language_registry.set_theme(cx.theme().clone());
|
||||
let language_registry = Arc::new(language_registry);
|
||||
languages::init(language_registry.clone(), fs, node_runtime, cx);
|
||||
Assets.load_fonts(cx).unwrap();
|
||||
|
||||
cx.activate(true);
|
||||
cx.open_window(WindowOptions::default(), |_, cx| {
|
||||
cx.new(|cx| MarkdownExample::new(MARKDOWN_EXAMPLE.into(), language_registry, cx))
|
||||
})
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
struct MarkdownExample {
|
||||
markdown: Entity<Markdown>,
|
||||
}
|
||||
|
||||
impl MarkdownExample {
|
||||
pub fn new(text: SharedString, language_registry: Arc<LanguageRegistry>, cx: &mut App) -> Self {
|
||||
let markdown = cx
|
||||
.new(|cx| Markdown::new(text, Some(language_registry), Some("TypeScript".into()), cx));
|
||||
Self { markdown }
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for MarkdownExample {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let markdown_style = MarkdownStyle {
|
||||
base_text_style: gpui::TextStyle {
|
||||
font_family: ".ZedSans".into(),
|
||||
color: cx.theme().colors().terminal_ansi_black,
|
||||
..Default::default()
|
||||
},
|
||||
code_block: StyleRefinement::default()
|
||||
.font_family(".ZedMono")
|
||||
.m(rems(1.))
|
||||
.bg(rgb(0xAAAAAAA)),
|
||||
inline_code: gpui::TextStyleRefinement {
|
||||
font_family: Some(".ZedMono".into()),
|
||||
color: Some(cx.theme().colors().editor_foreground),
|
||||
background_color: Some(cx.theme().colors().editor_background),
|
||||
..Default::default()
|
||||
},
|
||||
rule_color: Color::Muted.color(cx),
|
||||
block_quote_border_color: Color::Muted.color(cx),
|
||||
block_quote: gpui::TextStyleRefinement {
|
||||
color: Some(Color::Muted.color(cx)),
|
||||
..Default::default()
|
||||
},
|
||||
link: gpui::TextStyleRefinement {
|
||||
color: Some(Color::Accent.color(cx)),
|
||||
underline: Some(gpui::UnderlineStyle {
|
||||
thickness: px(1.),
|
||||
color: Some(Color::Accent.color(cx)),
|
||||
wavy: false,
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
syntax: cx.theme().syntax().clone(),
|
||||
selection_background_color: cx.theme().colors().element_selection_background,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
div()
|
||||
.id("markdown-example")
|
||||
.debug_selector(|| "foo".into())
|
||||
.relative()
|
||||
.bg(gpui::white())
|
||||
.size_full()
|
||||
.p_4()
|
||||
.overflow_y_scroll()
|
||||
.child(MarkdownElement::new(self.markdown.clone(), markdown_style))
|
||||
}
|
||||
}
|
||||
113
crates/markdown/examples/markdown_as_child.rs
Normal file
113
crates/markdown/examples/markdown_as_child.rs
Normal file
@@ -0,0 +1,113 @@
|
||||
use assets::Assets;
|
||||
use gpui::{Entity, KeyBinding, Length, StyleRefinement, WindowOptions, rgb};
|
||||
use language::LanguageRegistry;
|
||||
use markdown::{Markdown, MarkdownElement, MarkdownStyle};
|
||||
use node_runtime::NodeRuntime;
|
||||
use settings::SettingsStore;
|
||||
use std::sync::Arc;
|
||||
use theme::LoadThemes;
|
||||
use ui::div;
|
||||
use ui::prelude::*;
|
||||
|
||||
const MARKDOWN_EXAMPLE: &str = r#"
|
||||
this text should be selectable
|
||||
|
||||
wow so cool
|
||||
|
||||
## Heading 2
|
||||
"#;
|
||||
pub fn main() {
|
||||
env_logger::init();
|
||||
|
||||
gpui_platform::application().with_assets(Assets).run(|cx| {
|
||||
let store = SettingsStore::test(cx);
|
||||
cx.set_global(store);
|
||||
cx.bind_keys([KeyBinding::new("cmd-c", markdown::Copy, None)]);
|
||||
|
||||
let node_runtime = NodeRuntime::unavailable();
|
||||
let language_registry = Arc::new(LanguageRegistry::new(cx.background_executor().clone()));
|
||||
let fs = fs::FakeFs::new(cx.background_executor().clone());
|
||||
languages::init(language_registry, fs, node_runtime, cx);
|
||||
theme_settings::init(LoadThemes::JustBase, cx);
|
||||
Assets.load_fonts(cx).unwrap();
|
||||
|
||||
cx.activate(true);
|
||||
let _ = cx.open_window(WindowOptions::default(), |_, cx| {
|
||||
cx.new(|cx| {
|
||||
let markdown = cx.new(|cx| Markdown::new(MARKDOWN_EXAMPLE.into(), None, None, cx));
|
||||
|
||||
HelloWorld { markdown }
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
struct HelloWorld {
|
||||
markdown: Entity<Markdown>,
|
||||
}
|
||||
|
||||
impl Render for HelloWorld {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let markdown_style = MarkdownStyle {
|
||||
base_text_style: gpui::TextStyle {
|
||||
font_family: "Zed Mono".into(),
|
||||
color: cx.theme().colors().text,
|
||||
..Default::default()
|
||||
},
|
||||
code_block: StyleRefinement {
|
||||
text: gpui::TextStyleRefinement {
|
||||
font_family: Some("Zed Mono".into()),
|
||||
background_color: Some(cx.theme().colors().editor_background),
|
||||
..Default::default()
|
||||
},
|
||||
margin: gpui::EdgesRefinement {
|
||||
top: Some(Length::Definite(rems(4.).into())),
|
||||
left: Some(Length::Definite(rems(4.).into())),
|
||||
right: Some(Length::Definite(rems(4.).into())),
|
||||
bottom: Some(Length::Definite(rems(4.).into())),
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
inline_code: gpui::TextStyleRefinement {
|
||||
font_family: Some("Zed Mono".into()),
|
||||
background_color: Some(cx.theme().colors().editor_background),
|
||||
..Default::default()
|
||||
},
|
||||
rule_color: Color::Muted.color(cx),
|
||||
block_quote_border_color: Color::Muted.color(cx),
|
||||
block_quote: gpui::TextStyleRefinement {
|
||||
color: Some(Color::Muted.color(cx)),
|
||||
..Default::default()
|
||||
},
|
||||
link: gpui::TextStyleRefinement {
|
||||
color: Some(Color::Accent.color(cx)),
|
||||
underline: Some(gpui::UnderlineStyle {
|
||||
thickness: px(1.),
|
||||
color: Some(Color::Accent.color(cx)),
|
||||
wavy: false,
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
syntax: cx.theme().syntax().clone(),
|
||||
selection_background_color: cx.theme().colors().element_selection_background,
|
||||
heading: Default::default(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
div()
|
||||
.flex()
|
||||
.bg(rgb(0x2e7d32))
|
||||
.size(Length::Definite(px(700.0).into()))
|
||||
.justify_center()
|
||||
.items_center()
|
||||
.shadow_lg()
|
||||
.border_1()
|
||||
.border_color(rgb(0x0000ff))
|
||||
.text_xl()
|
||||
.text_color(rgb(0xffffff))
|
||||
.child(
|
||||
div()
|
||||
.child(MarkdownElement::new(self.markdown.clone(), markdown_style))
|
||||
.p_20(),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user