Skip to content

Commit 07e3cc7

Browse files
committed
refactor spawn/task, line input/text area, scoll ux
1 parent 20a4da8 commit 07e3cc7

56 files changed

Lines changed: 2160 additions & 1132 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

shell/gpui/src/diff/diff_view/find_bar.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ use crate::app::fonts;
77
use crate::app::theme::Theme;
88
use crate::repo::window::RepoWindow;
99
use crate::ui::icons::{self, glyph};
10-
use crate::ui::input::{LineEdit, line_edit_content};
10+
use crate::ui::input::{LineInput, line_input_content};
1111

1212
pub(super) fn render_find_bar(
13-
query: &LineEdit,
13+
query: &LineInput,
1414
match_count: usize,
1515
match_current: usize,
16-
caret_visible: bool,
1716
t: &Theme,
1817
cx: &mut Context<RepoWindow>,
1918
) -> AnyElement {
@@ -35,7 +34,7 @@ pub(super) fn render_find_bar(
3534
.border_b_1()
3635
.border_color(rgb(t.border))
3736
.child(icons::icon(glyph::SEARCH, 12., t.fg_dim))
38-
.child(search_input(query, caret_visible, t))
37+
.child(search_input(query, t))
3938
.child(
4039
div()
4140
.flex_none()
@@ -47,7 +46,7 @@ pub(super) fn render_find_bar(
4746
.into_any_element()
4847
}
4948

50-
fn search_input(query: &LineEdit, caret_visible: bool, t: &Theme) -> AnyElement {
49+
fn search_input(query: &LineInput, t: &Theme) -> AnyElement {
5150
let mut input = div()
5251
.flex()
5352
.flex_row()
@@ -58,13 +57,7 @@ fn search_input(query: &LineEdit, caret_visible: bool, t: &Theme) -> AnyElement
5857
.text_size(px(12.))
5958
.font_family(fonts::mono());
6059

61-
input = input.child(line_edit_content(
62-
query,
63-
"Type to find...",
64-
caret_visible,
65-
t,
66-
None,
67-
));
60+
input = input.child(line_input_content(query, "Type to find...", t, None));
6861

6962
input.into_any_element()
7063
}

shell/gpui/src/diff/diff_view/render.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,9 @@ pub fn diff_view(
9898
}
9999
};
100100

101-
let find_bar = find.query.map(|q| {
102-
render_find_bar(
103-
q,
104-
find.match_count,
105-
find.match_current,
106-
find.caret_visible,
107-
&t,
108-
cx,
109-
)
110-
});
101+
let find_bar = find
102+
.query
103+
.map(|q| render_find_bar(q, find.match_count, find.match_current, &t, cx));
111104

112105
let mut root = div()
113106
.flex()

shell/gpui/src/diff/diff_view/sbs_body.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use super::mouse::{attach_selection_handlers, bounds_capture};
1111
use crate::app::fonts;
1212
use crate::app::theme::Theme;
1313
use crate::diff::SbsSide;
14+
use crate::diff::line::ROW_HEIGHT;
1415
use crate::diff::side_by_side::{
1516
SBS_GUTTER_WIDTH, sbs_new_content, sbs_new_gutter, sbs_old_content, sbs_old_gutter,
1617
};
@@ -19,6 +20,7 @@ use crate::diff::wrap::{
1920
};
2021
use crate::repo::window::{PanelBoundsSlot, RepoWindow};
2122
use crate::ui::primitives::no_scrollbar_gutter;
23+
use crate::ui::scrollbar::vertical_uniform_scrollbar;
2224

2325
pub(super) fn side_by_side_body(
2426
fd: &FileDiff,
@@ -88,7 +90,7 @@ pub(super) fn side_by_side_body(
8890
rows,
8991
theme: theme.clone(),
9092
query,
91-
scroll,
93+
scroll: scroll.clone(),
9294
side: SbsSide::New,
9395
bounds: new_bounds.clone(),
9496
advance,
@@ -108,13 +110,14 @@ pub(super) fn side_by_side_body(
108110
let content_panel = |list: UniformList,
109111
bounds: PanelBoundsSlot,
110112
side: SbsSide,
113+
show_scrollbar: bool,
111114
cx: &mut Context<RepoWindow>| {
112-
div()
115+
let mut panel = div()
113116
.relative()
114117
.flex_1()
115118
.min_w_0()
116119
.h_full()
117-
.child(bounds_capture(bounds))
120+
.child(bounds_capture(bounds.clone()))
118121
.on_mouse_up(
119122
MouseButton::Left,
120123
cx.listener(move |v, _: &MouseUpEvent, _, cx| {
@@ -126,7 +129,17 @@ pub(super) fn side_by_side_body(
126129
}
127130
}),
128131
)
129-
.child(no_scrollbar_gutter(list).h_full())
132+
.child(no_scrollbar_gutter(list).h_full());
133+
if show_scrollbar {
134+
panel = panel.child(vertical_uniform_scrollbar(
135+
scroll.clone(),
136+
bounds,
137+
px(count as f32 * ROW_HEIGHT),
138+
theme.as_ref(),
139+
cx,
140+
));
141+
}
142+
panel
130143
};
131144

132145
div()
@@ -135,10 +148,22 @@ pub(super) fn side_by_side_body(
135148
.h_full()
136149
.min_h_0()
137150
.child(gutter_panel(old_gutter))
138-
.child(content_panel(old_content, old_bounds, SbsSide::Old, cx))
151+
.child(content_panel(
152+
old_content,
153+
old_bounds,
154+
SbsSide::Old,
155+
false,
156+
cx,
157+
))
139158
.child(div().flex_none().w(px(1.)).h_full().bg(rgb(theme.border)))
140159
.child(gutter_panel(new_gutter))
141-
.child(content_panel(new_content, new_bounds, SbsSide::New, cx))
160+
.child(content_panel(
161+
new_content,
162+
new_bounds,
163+
SbsSide::New,
164+
true,
165+
cx,
166+
))
142167
.into_any_element()
143168
}
144169

shell/gpui/src/diff/diff_view/state.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use jayjay_core::DiffHunk;
22
use jayjay_core::diff::FileDiff;
33

44
use crate::repo::window::PanelBoundsSlot;
5-
use crate::ui::input::LineEdit;
5+
use crate::ui::input::LineInput;
66

77
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
88
pub enum DiffViewMode {
@@ -32,8 +32,7 @@ pub struct DiffViewState<'a> {
3232

3333
/// Find-in-diff state.
3434
pub struct FindState<'a> {
35-
pub query: Option<&'a LineEdit>,
35+
pub query: Option<&'a LineInput>,
3636
pub match_count: usize,
3737
pub match_current: usize,
38-
pub caret_visible: bool,
3938
}

shell/gpui/src/diff/diff_view/unified_body.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ use super::mouse::{attach_selection_handlers, bounds_capture};
1010
use crate::app::fonts;
1111
use crate::app::theme::Theme;
1212
use crate::diff::SbsSide;
13-
use crate::diff::line::{GUTTER_WIDTH, content_row, gutter_row};
13+
use crate::diff::line::{GUTTER_WIDTH, ROW_HEIGHT, content_row, gutter_row};
1414
use crate::diff::wrap::{selection_cols_in_fragment, wrap_cols_from_bounds, wrap_diff_lines};
1515
use crate::repo::window::{PanelBoundsSlot, RepoWindow};
1616
use crate::ui::primitives::no_scrollbar_gutter;
17+
use crate::ui::scrollbar::vertical_uniform_scrollbar;
1718

1819
pub(super) fn unified_body(
1920
fd: &FileDiff,
@@ -119,7 +120,14 @@ pub(super) fn unified_body(
119120
v.finish_diff_selection(cx);
120121
}),
121122
)
122-
.child(no_scrollbar_gutter(content).h_full()),
123+
.child(no_scrollbar_gutter(content).h_full())
124+
.child(vertical_uniform_scrollbar(
125+
scroll,
126+
bounds_slot,
127+
px(count as f32 * ROW_HEIGHT),
128+
theme.as_ref(),
129+
cx,
130+
)),
123131
)
124132
.into_any_element()
125133
}

shell/gpui/src/repo/toggles.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use gpui::{AppContext, Context};
3+
use gpui::Context;
44
use jayjay_core::dag::DagLayout;
55
use jayjay_core::{DEFAULT_REVSET_DEPTH, build_default_revset};
66

@@ -41,11 +41,10 @@ impl RepoViewModel {
4141
self.clear_error();
4242
cx.notify();
4343

44-
cx.spawn(async move |this, cx| {
45-
let result = cx
46-
.background_spawn(async move { repo.log_graph(&build_default_revset(new_depth)) })
47-
.await;
48-
let _ = this.update(cx, move |vm, cx| {
44+
Self::background_update(
45+
cx,
46+
async move { repo.log_graph(&build_default_revset(new_depth)) },
47+
move |vm, result, cx| {
4948
vm.loading.more = false;
5049
match result {
5150
Ok(entries) => {
@@ -57,9 +56,8 @@ impl RepoViewModel {
5756
Err(error) => vm.present_error(error),
5857
}
5958
cx.notify();
60-
});
61-
})
62-
.detach();
59+
},
60+
);
6361
}
6462

6563
pub fn toggle_annotate(&mut self, cx: &mut Context<Self>) {

0 commit comments

Comments
 (0)