feat: add diff view component

This commit is contained in:
2026-11-06 08:01:23 +07:00
parent f272f80d09
commit 7214c70ea7
11 changed files with 1067 additions and 35 deletions
+20 -6
View File
@@ -1,3 +1,4 @@
use std::sync::Arc;
use std::time::Duration;
use std::time::Instant;
@@ -54,9 +55,9 @@ struct AutohideState {
}
impl Autohide {
pub(crate) fn new(window: &mut Window, cx: &mut App) -> Self {
pub(crate) fn new(key: ElementId, window: &mut Window, cx: &mut App) -> Self {
let view = window.current_view();
let state = window.use_keyed_state("scrollbar-autohide", cx, |_, _| AutohideState {
let state = window.use_keyed_state(key, cx, |_, _| AutohideState {
last_activity: None,
hide_task: None,
});
@@ -195,6 +196,11 @@ impl ScrollArea {
}
}
/// Names keyed state under the scrollbar's own id.
pub fn scrollbar_state_key(name: &'static str, id: &ElementId) -> ElementId {
ElementId::NamedChild(Arc::new(id.clone()), SharedString::from(name))
}
/// Pure thumb geometry for an overlay scrollbar.
pub(crate) fn thumb_geometry(
viewport: Pixels,
@@ -247,11 +253,12 @@ impl RenderOnce for ScrollArea {
ScrollbarVisibility::Always => false,
ScrollbarVisibility::Autohide => true,
};
let id = self.id.clone();
wrapper.extend(std::iter::once(
canvas(|_, _, _| {}, {
let handle = handle.clone();
move |_, _, window, cx| {
paint_scrollbar(&handle, autohide, window, cx);
paint_scrollbar(&handle, &id, autohide, window, cx);
}
})
.absolute()
@@ -265,7 +272,13 @@ impl RenderOnce for ScrollArea {
}
/// Paints the overlay scrollbar thumb.
fn paint_scrollbar(handle: &ScrollHandle, autohide: bool, window: &mut Window, cx: &mut App) {
fn paint_scrollbar(
handle: &ScrollHandle,
key: &ElementId,
autohide: bool,
window: &mut Window,
cx: &mut App,
) {
let theme = cx.theme();
let view = window.current_view();
@@ -281,8 +294,9 @@ fn paint_scrollbar(handle: &ScrollHandle, autohide: bool, window: &mut Window, c
return;
}
let autohide_state = autohide.then(|| Autohide::new(window, cx));
let drag = window.use_keyed_state("scrollbar-thumb-drag", cx, |_, _| {
let autohide_state =
autohide.then(|| Autohide::new(scrollbar_state_key("autohide", key), window, cx));
let drag = window.use_keyed_state(scrollbar_state_key("thumb-drag", key), cx, |_, _| {
Option::<(Pixels, Pixels)>::None
});
let dragging = drag.read(cx).is_some();