
Closes #32354 The issue is that we render selections over the text in the agent panel, but under the text in editor, so themes that have no alpha for the selection background color (defaults to 0xff) will just occlude the selected region. Making the selection render under the text in markdown would be a significant (and complicated) refactor, as selections can cross element boundaries (i.e. spanning code block and a header after the code block). The solution is to add a new highlight to themes `element_selection_background` that defaults to the local players selection background with an alpha of 0.25 (roughly equal to 0x3D which is the alpha we use for selection backgrounds in default themes) if the alpha of the local players selection is 1.0. The idea here is to give theme authors more control over how the selections look outside of editor, as in the agent panel specifically, the background color is different, so while an alpha of 0.25 looks acceptable, a different color would likely be better. CC: @iamnbutler. Would appreciate your thoughts on this. > Note: Before and after using Everforest theme | Before | After | |-------| -----| | <img width="618" alt="Screenshot 2025-06-09 at 5 23 10 PM" src="https://github.com/user-attachments/assets/41c7aa02-5b3f-45c6-981c-646ab9e2a1f3" /> | <img width="618" alt="Screenshot 2025-06-09 at 5 25 03 PM" src="https://github.com/user-attachments/assets/dfb13ffc-1559-4f01-98f1-a7aea68079b7" /> | Clearly, the selection in the after doesn't look _that_ great, but it is better than the before, and this PR makes the color of the selection configurable by the theme so that this theme author could make it a lighter color for better contrast. Release Notes: - agent panel: Fixed an issue with some themes where selections inside the agent panel would occlude the selected text completely Co-authored-by: Antonio <me@as-cii.com>
124 lines
7.4 KiB
Rust
124 lines
7.4 KiB
Rust
use assets::Assets;
|
|
use gpui::{Application, Entity, KeyBinding, StyleRefinement, WindowOptions, prelude::*, rgb};
|
|
use language::{LanguageRegistry, language_settings::AllLanguageSettings};
|
|
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();
|
|
Application::new().with_assets(Assets).run(|cx| {
|
|
let store = SettingsStore::test(cx);
|
|
cx.set_global(store);
|
|
language::init(cx);
|
|
SettingsStore::update(cx, |store, cx| {
|
|
store.update_user_settings::<AllLanguageSettings>(cx, |_| {});
|
|
});
|
|
cx.bind_keys([KeyBinding::new("cmd-c", markdown::Copy, None)]);
|
|
|
|
let node_runtime = NodeRuntime::unavailable();
|
|
theme::init(LoadThemes::JustBase, cx);
|
|
|
|
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(), 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: "Zed Plex Sans".into(),
|
|
color: cx.theme().colors().terminal_ansi_black,
|
|
..Default::default()
|
|
},
|
|
code_block: StyleRefinement::default()
|
|
.font_family("Zed Plex Mono")
|
|
.m(rems(1.))
|
|
.bg(rgb(0xAAAAAAA)),
|
|
inline_code: gpui::TextStyleRefinement {
|
|
font_family: Some("Zed Mono".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))
|
|
}
|
|
}
|