Use 'ui.text' as a base style for the syntax highlighter

This fixes a regression from the refactor of the highlighters when
switching to tree-house. The old `StyleIter` used `renderer.text_style`
as the base style rather than `Style::default()` for syntax highlights.
The result was that any text not captured by a syntax highlight query
was styled with no foreground or background, defaulting to the
terminal's foreground/background. This could cause text in markdown
files to look off-colored depending on your terminal configuration.
(Though you wouldn't notice if your 'ui.text' theming matches your
terminal's theming.)
pull/13551/head
Michael Davis 2025-05-16 10:52:46 -04:00
parent b4e51ef895
commit 3ceae88c3a
No known key found for this signature in database
1 changed files with 12 additions and 4 deletions

View File

@ -77,7 +77,8 @@ pub fn render_text(
let mut formatter =
DocumentFormatter::new_at_prev_checkpoint(text, text_fmt, text_annotations, anchor);
let mut syntax_highlighter = SyntaxHighlighter::new(syntax_highlighter, text, theme);
let mut syntax_highlighter =
SyntaxHighlighter::new(syntax_highlighter, text, theme, renderer.text_style);
let mut overlay_highlighter = OverlayHighlighter::new(overlay_highlights, theme);
let mut last_line_pos = LinePos {
@ -477,17 +478,24 @@ struct SyntaxHighlighter<'h, 'r, 't> {
/// finished.
pos: usize,
theme: &'t Theme,
text_style: Style,
style: Style,
}
impl<'h, 'r, 't> SyntaxHighlighter<'h, 'r, 't> {
fn new(inner: Option<Highlighter<'h>>, text: RopeSlice<'r>, theme: &'t Theme) -> Self {
fn new(
inner: Option<Highlighter<'h>>,
text: RopeSlice<'r>,
theme: &'t Theme,
text_style: Style,
) -> Self {
let mut highlighter = Self {
inner,
text,
pos: 0,
theme,
style: Style::default(),
style: text_style,
text_style,
};
highlighter.update_pos();
highlighter
@ -516,7 +524,7 @@ impl<'h, 'r, 't> SyntaxHighlighter<'h, 'r, 't> {
let (event, highlights) = highlighter.advance();
let base = match event {
HighlightEvent::Refresh => Style::default(),
HighlightEvent::Refresh => self.text_style,
HighlightEvent::Push => self.style,
};