Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,9 @@ pub struct AppSettings {
pub sql_editor_hover_enabled: bool,
#[serde(default = "default_monospace_font_family")]
pub table_preview_font_family: String,
/// Markdown 编辑器代码字体(行内代码、代码块、表格内代码)。
#[serde(default = "default_monospace_font_family")]
pub markdown_code_font_family: String,
#[serde(default = "default_monospace_font_family")]
pub terminal_font_family: String,
#[serde(
Expand Down Expand Up @@ -1480,6 +1483,7 @@ impl Default for AppSettings {
sql_editor_font_size: default_sql_editor_font_size(),
sql_editor_hover_enabled: default_sql_editor_hover_enabled(),
table_preview_font_family: default_monospace_font_family(),
markdown_code_font_family: default_monospace_font_family(),
terminal_font_family: default_monospace_font_family(),
custom_fonts: Vec::new(),
terminal_font_size: default_terminal_font_size(),
Expand Down Expand Up @@ -1619,6 +1623,8 @@ impl AppSettings {
normalize_grid_monospace_font_family(&self.sql_editor_font_family);
self.table_preview_font_family =
normalize_grid_monospace_font_family(&self.table_preview_font_family);
self.markdown_code_font_family =
normalize_grid_monospace_font_family(&self.markdown_code_font_family);
self.terminal_font_family =
normalize_grid_monospace_font_family(&self.terminal_font_family);
}
Expand Down
9 changes: 8 additions & 1 deletion crates/markdown-editor/src/components/block/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fn build_text_runs(
link_color: Hsla,
code_bg: Hsla,
show_inline_code_backgrounds: bool,
code_font: &Font,
) -> Vec<TextRun> {
let spans = input.inline_spans();
let mut boundaries = vec![0, display_text.len()];
Expand Down Expand Up @@ -101,7 +102,11 @@ fn build_text_runs(
.map(|range| start < range.end && range.start < end)
.unwrap_or(false);

let mut font = base_run.font.clone();
let mut font = if inline_style.code {
code_font.clone()
} else {
base_run.font.clone()
};
if inline_style.bold && font.weight < FontWeight::BOLD {
font.weight = FontWeight::BOLD;
}
Expand Down Expand Up @@ -733,6 +738,7 @@ impl Element for BlockTextElement {
theme.colors.text_link,
theme.colors.code_bg,
show_inline_code_backgrounds,
&crate::fonts::FontSettings::code_font(cx),
)
}
} else {
Expand Down Expand Up @@ -1343,6 +1349,7 @@ mod tests {
rgba(0x0066ccff).into(),
rgba(0x111111ff).into(),
true,
&base_run.font,
);
let marked_run = runs.last().expect("styled text should create a final run");

Expand Down
11 changes: 8 additions & 3 deletions crates/markdown-editor/src/components/block/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,19 @@ impl EntityInputHandler for Block {
};
let (line_idx, y_in_line) =
element::wrapped_line_for_y(lines, self.last_line_height, relative.y)?;
let layout = &lines[line_idx];
let (Some(layout), Some(range)) = (lines.get(line_idx), ranges.get(line_idx)) else {
return None;
};
let origin_x = element::aligned_line_left(layout, bounds, self.text_align());
let utf8_offset_in_line = match layout
.closest_index_for_position(point(pt.x - origin_x, y_in_line), self.last_line_height)
{
Ok(idx) | Err(idx) => idx,
};
let utf8_index = ranges[line_idx].start + utf8_offset_in_line;
Some(Self::utf8_to_utf16_in(self.display_text(), utf8_index))
let utf8_index = crate::text_offsets::floor_char_boundary(
text,
range.start + utf8_offset_in_line.min(range.len()),
);
Some(Self::utf8_to_utf16_in(text, utf8_index))
}
}
22 changes: 22 additions & 0 deletions crates/markdown-editor/src/components/block/interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! parent editor via `BlockEvent` emissions.

use gpui::*;
use unicode_segmentation::UnicodeSegmentation;

use super::CollapsedCaretAffinity;
use super::{
Expand Down Expand Up @@ -858,6 +859,27 @@ impl Block {
let offset = self.index_for_mouse_position(event.position);
let was_focused = self.focus_handle.is_focused(window);

// Double click to select a word
if event.button == MouseButton::Left && event.click_count == 2 {
let text = self.display_text();

let range = text
.split_word_bound_indices()
.find(|(start, segment)| {
let end = start + segment.len();
*start <= offset && offset < end
})
.map(|(start, segment)| start..start + segment.len());

if let Some(range) = range {
self.selected_range = range;
}

cx.notify();

return;
}

// Cmd/Ctrl+click follows a rendered link instead of editing it, so the
// block is neither focused nor selected; the link opens on mouse-up.
if event.modifiers.secondary() && self.pointer_link_hit(event.position).is_some() {
Expand Down
Loading
Loading