Merge branch 'main' into editor2_tests

This commit is contained in:
Marshall Bowers
2023-12-04 14:09:23 -05:00
70 changed files with 3367 additions and 6799 deletions
+43 -49
View File
@@ -100,8 +100,10 @@ use text::{OffsetUtf16, Rope};
use theme::{
ActiveTheme, DiagnosticStyle, PlayerColor, SyntaxTheme, Theme, ThemeColors, ThemeSettings,
};
use ui::prelude::*;
use ui::{h_stack, v_stack, HighlightedLabel, IconButton, Popover, Tooltip};
use ui::{
h_stack, v_stack, ButtonSize, ButtonStyle, HighlightedLabel, Icon, IconButton, Popover, Tooltip,
};
use ui::{prelude::*, IconSize};
use util::{post_inc, RangeExt, ResultExt, TryFutureExt};
use workspace::{
item::{ItemEvent, ItemHandle},
@@ -154,7 +156,6 @@ pub fn render_parsed_markdown(
}
}),
);
let runs = text_runs_for_highlights(&parsed.text, &editor_style.text, highlights);
let mut links = Vec::new();
let mut link_ranges = Vec::new();
@@ -167,7 +168,7 @@ pub fn render_parsed_markdown(
InteractiveText::new(
element_id,
StyledText::new(parsed.text.clone()).with_runs(runs),
StyledText::new(parsed.text.clone()).with_highlights(&editor_style.text, highlights),
)
.on_click(link_ranges, move |clicked_range_ix, cx| {
match &links[clicked_range_ix] {
@@ -1199,11 +1200,7 @@ impl CompletionsMenu {
),
);
let completion_label = StyledText::new(completion.label.text.clone())
.with_runs(text_runs_for_highlights(
&completion.label.text,
&style.text,
highlights,
));
.with_highlights(&style.text, highlights);
let documentation_label =
if let Some(Documentation::SingleLine(text)) = documentation {
Some(SharedString::from(text.clone()))
@@ -1925,14 +1922,14 @@ impl Editor {
// self.buffer.read(cx).read(cx).file_at(point).cloned()
// }
// pub fn active_excerpt(
// &self,
// cx: &AppContext,
// ) -> Option<(ExcerptId, Model<Buffer>, Range<text::Anchor>)> {
// self.buffer
// .read(cx)
// .excerpt_containing(self.selections.newest_anchor().head(), cx)
// }
pub fn active_excerpt(
&self,
cx: &AppContext,
) -> Option<(ExcerptId, Model<Buffer>, Range<text::Anchor>)> {
self.buffer
.read(cx)
.excerpt_containing(self.selections.newest_anchor().head(), cx)
}
// pub fn style(&self, cx: &AppContext) -> EditorStyle {
// build_style(
@@ -9699,20 +9696,42 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend
let message = diagnostic.message;
Arc::new(move |cx: &mut BlockContext| {
let message = message.clone();
let copy_id: SharedString = format!("copy-{}", cx.block_id.clone()).to_string().into();
let write_to_clipboard = cx.write_to_clipboard(ClipboardItem::new(message.clone()));
// TODO: Nate: We should tint the background of the block with the severity color
// We need to extend the theme before we can do this
v_stack()
.id(cx.block_id)
.relative()
.size_full()
.bg(gpui::red())
.children(highlighted_lines.iter().map(|(line, highlights)| {
div()
let group_id = cx.block_id.to_string();
h_stack()
.group(group_id.clone())
.gap_2()
.absolute()
.left(cx.anchor_x)
.px_1p5()
.child(HighlightedLabel::new(line.clone(), highlights.clone()))
.ml(cx.anchor_x)
.child(
div()
.border()
.border_color(gpui::red())
.invisible()
.group_hover(group_id, |style| style.visible())
.child(
IconButton::new(copy_id.clone(), Icon::Copy)
.icon_color(Color::Muted)
.size(ButtonSize::Compact)
.style(ButtonStyle::Transparent)
.on_click(cx.listener(move |_, _, cx| write_to_clipboard))
.tooltip(|cx| Tooltip::text("Copy diagnostic message", cx)),
),
)
}))
.cursor_pointer()
.on_click(cx.listener(move |_, _, cx| {
cx.write_to_clipboard(ClipboardItem::new(message.clone()));
}))
.tooltip(|cx| Tooltip::text("Copy diagnostic message", cx))
.into_any_element()
})
}
@@ -9760,31 +9779,6 @@ pub fn diagnostic_style(
}
}
pub fn text_runs_for_highlights(
text: &str,
default_style: &TextStyle,
highlights: impl IntoIterator<Item = (Range<usize>, HighlightStyle)>,
) -> Vec<TextRun> {
let mut runs = Vec::new();
let mut ix = 0;
for (range, highlight) in highlights {
if ix < range.start {
runs.push(default_style.clone().to_run(range.start - ix));
}
runs.push(
default_style
.clone()
.highlight(highlight)
.to_run(range.len()),
);
ix = range.end;
}
if ix < text.len() {
runs.push(default_style.to_run(text.len() - ix));
}
runs
}
pub fn styled_runs_for_code_label<'a>(
label: &'a CodeLabel,
syntax_theme: &'a theme::SyntaxTheme,
+108 -22
View File
@@ -51,8 +51,10 @@ use std::{
};
use sum_tree::Bias;
use theme::{ActiveTheme, PlayerColor};
use ui::prelude::*;
use ui::{h_stack, IconButton, Tooltip};
use ui::{
h_stack, ButtonLike, ButtonStyle, Disclosure, IconButton, IconElement, IconSize, Label, Tooltip,
};
use ui::{prelude::*, Icon};
use util::ResultExt;
use workspace::item::Item;
@@ -2223,7 +2225,8 @@ impl EditorElement {
.as_ref()
.map(|project| project.read(cx).visible_worktrees(cx).count() > 1)
.unwrap_or_default();
let jump_icon = project::File::from_dyn(buffer.file()).map(|file| {
let jump_handler = project::File::from_dyn(buffer.file()).map(|file| {
let jump_path = ProjectPath {
worktree_id: file.worktree_id(cx),
path: file.path.clone(),
@@ -2234,11 +2237,11 @@ impl EditorElement {
.map_or(range.context.start, |primary| primary.start);
let jump_position = language::ToPoint::to_point(&jump_anchor, buffer);
IconButton::new(block_id, ui::Icon::ArrowUpRight)
.on_click(cx.listener_for(&self.editor, move |editor, e, cx| {
editor.jump(jump_path.clone(), jump_position, jump_anchor, cx);
}))
.tooltip(|cx| Tooltip::for_action("Jump to Buffer", &OpenExcerpts, cx))
let jump_handler = cx.listener_for(&self.editor, move |editor, e, cx| {
editor.jump(jump_path.clone(), jump_position, jump_anchor, cx);
});
jump_handler
});
let element = if *starts_new_buffer {
@@ -2253,25 +2256,108 @@ impl EditorElement {
.map(|p| SharedString::from(p.to_string_lossy().to_string() + "/"));
}
h_stack()
.id("path header block")
.size_full()
.bg(gpui::red())
.child(
filename
.map(SharedString::from)
.unwrap_or_else(|| "untitled".into()),
)
.children(parent_path)
.children(jump_icon) // .p_x(gutter_padding)
let is_open = true;
div().id("path header container").size_full().p_1p5().child(
h_stack()
.id("path header block")
.py_1p5()
.pl_3()
.pr_2()
.rounded_lg()
.shadow_md()
.border()
.border_color(cx.theme().colors().border)
.bg(cx.theme().colors().editor_subheader_background)
.justify_between()
.cursor_pointer()
.hover(|style| style.bg(cx.theme().colors().element_hover))
.on_click(cx.listener(|_editor, _event, _cx| {
// TODO: Implement collapsing path headers
todo!("Clicking path header")
}))
.child(
h_stack()
.gap_3()
// TODO: Add open/close state and toggle action
.child(
div().border().border_color(gpui::red()).child(
ButtonLike::new("path-header-disclosure-control")
.style(ButtonStyle::Subtle)
.child(IconElement::new(match is_open {
true => Icon::ChevronDown,
false => Icon::ChevronRight,
})),
),
)
.child(
h_stack()
.gap_2()
.child(Label::new(
filename
.map(SharedString::from)
.unwrap_or_else(|| "untitled".into()),
))
.when_some(parent_path, |then, path| {
then.child(Label::new(path).color(Color::Muted))
}),
),
)
.children(jump_handler.map(|jump_handler| {
IconButton::new(block_id, Icon::ArrowUpRight)
.style(ButtonStyle::Subtle)
.on_click(jump_handler)
.tooltip(|cx| {
Tooltip::for_action("Jump to Buffer", &OpenExcerpts, cx)
})
})), // .p_x(gutter_padding)
)
} else {
let text_style = style.text.clone();
h_stack()
.id("collapsed context")
.size_full()
.bg(gpui::red())
.child("⋯")
.children(jump_icon) // .p_x(gutter_padding)
.gap(gutter_padding)
.child(
h_stack()
.justify_end()
.flex_none()
.w(gutter_width - gutter_padding)
.h_full()
.text_buffer(cx)
.text_color(cx.theme().colors().editor_line_number)
.child("..."),
)
.map(|this| {
if let Some(jump_handler) = jump_handler {
this.child(
ButtonLike::new("jump to collapsed context")
.style(ButtonStyle::Transparent)
.full_width()
.on_click(jump_handler)
.tooltip(|cx| {
Tooltip::for_action(
"Jump to Buffer",
&OpenExcerpts,
cx,
)
})
.child(
div()
.h_px()
.w_full()
.bg(cx.theme().colors().border_variant)
.group_hover("", |style| {
style.bg(cx.theme().colors().border)
}),
),
)
} else {
this.child(div().size_full().bg(gpui::green()))
}
})
// .child("⋯")
// .children(jump_icon) // .p_x(gutter_padding)
};
element.into_any()
}