feat: subtext under pr title

This commit is contained in:
2026-05-12 01:34:33 +08:00
parent bfcfac61e8
commit 2fe3f7b94f
12 changed files with 290 additions and 105 deletions

View File

@@ -1,6 +1,6 @@
use gpui::{
AppContext, InteractiveElement, IntoElement, ParentElement, StatefulInteractiveElement, Styled,
div, prelude::FluentBuilder,
div, img, prelude::FluentBuilder,
};
use crate::{
@@ -118,20 +118,80 @@ impl PullRequestView {
}
}
let author_pill = div()
.px_2()
.border_1()
.border_color(theme.colors.border)
.rounded_full()
.bg(theme.colors.surface_elevated)
.child(text("kennethnym").text_xs());
let merge_text = match (
pr.author.as_ref(),
pr.base_branch_name.as_ref(),
pr.head_branch_name.as_ref(),
) {
| (Some(author), Some(base_branch), Some(head_branch)) => {
let str = format!(
"{} requested to merge {} into {}",
author.login, head_branch, base_branch
);
let row = div()
.flex()
.flex_row()
.gap_2()
.child(status_pill)
.child(author_pill);
let head_branch_text_offset = author.login.len() + 20;
let base_branch_text_offset = head_branch_text_offset + head_branch.len() + 6;
let highlights = [
(
0..author.login.len(),
gpui::HighlightStyle {
font_weight: Some(gpui::FontWeight::BOLD),
..Default::default()
},
),
(
head_branch_text_offset..head_branch_text_offset + head_branch.len(),
gpui::HighlightStyle {
font_weight: Some(gpui::FontWeight::BOLD),
color: Some(theme.colors.accent.into()),
..Default::default()
},
),
(
base_branch_text_offset..base_branch_text_offset + base_branch.len(),
gpui::HighlightStyle {
font_weight: Some(gpui::FontWeight::BOLD),
color: Some(theme.colors.accent.into()),
..Default::default()
},
),
];
Some((
author,
gpui::StyledText::new(str).with_highlights(highlights),
))
}
| _ => None,
};
let metadata_line =
div()
.flex()
.flex_row()
.gap_2()
.when_some(merge_text, |it, (author, t)| {
it.child(
div()
.flex()
.flex_row()
.items_center()
.gap_1p5()
.child(img(author.avatar_url.clone()).size_4().rounded_full())
.child(
div()
.min_w_0()
.w_full()
.text_color(theme.colors.text)
.text_xs()
.font_weight(gpui::FontWeight::LIGHT)
.opacity(0.8)
.child(t),
),
)
});
div()
.size_full()
@@ -145,8 +205,8 @@ impl PullRequestView {
.py_3()
.border_b_1()
.border_color(theme.colors.border)
.child(text(pr.title.clone()).w_full().text_xl().mb_2())
.child(row),
.child(text(pr.title.clone()).w_full().text_xl().mb_1())
.child(metadata_line),
)
.child(
div().flex_1().min_h_0().w_full().child(

View File

@@ -43,9 +43,9 @@ impl Screen {
_ = cx
.subscribe(&self.issue_list, |this, _, event, cx| match event {
issue_list::Event::ItemSelected(pr_id) => {
this.handle_issue_list_item_selected(pr_id, cx);
}
| issue_list::Event::ItemSelected(pr_id) => {
this.handle_issue_list_item_selected(pr_id, cx);
}
})
.detach();
}
@@ -56,17 +56,18 @@ impl Screen {
cx: &mut gpui::Context<Self>,
) {
match value {
SidebarItemValue::PullRequest { filter } => {
self.issue_filter = Some(*filter);
cx.notify();
}
| SidebarItemValue::PullRequest { filter } => {
self.issue_filter = Some(*filter);
cx.notify();
}
}
}
fn handle_issue_list_item_selected(
&mut self,
id: &api::issues::Id,
cx: &mut gpui::Context<Self>, ) {
cx: &mut gpui::Context<Self>,
) {
println!("handle issue list item selected: {:?}", id);
self.pull_request_view.update(cx, |view, cx| {
view.change_displayed_pull_request(id.clone(), cx);
@@ -111,7 +112,6 @@ impl gpui::Render for Screen {
.bg(theme.colors.surface)
.border_x_1()
.border_color(theme.colors.border)
.mr_2()
.overflow_hidden()
.child(self.issue_list.clone()),
)
@@ -123,8 +123,6 @@ impl gpui::Render for Screen {
.h_full()
.overflow_hidden()
.bg(theme.colors.surface)
.border_l_1()
.border_color(theme.colors.border)
.child(self.pull_request_view.clone()),
),
)