Skip to content

Commit 50c0e71

Browse files
ConradIrwindive
authored andcommitted
Revert "ui: Account for padding of parent container during scrollbar layout (zed-industries#27402)" (zed-industries#30544)
This reverts commit 82a7aca. Release Notes: - N/A
1 parent 3ea30a7 commit 50c0e71

File tree

4 files changed

+204
-126
lines changed

4 files changed

+204
-126
lines changed

crates/gpui/src/elements/div.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,20 +1559,32 @@ impl Interactivity {
15591559
) -> Point<Pixels> {
15601560
if let Some(scroll_offset) = self.scroll_offset.as_ref() {
15611561
let mut scroll_to_bottom = false;
1562-
let mut tracked_scroll_handle = self
1563-
.tracked_scroll_handle
1564-
.as_ref()
1565-
.map(|handle| handle.0.borrow_mut());
1566-
if let Some(mut scroll_handle_state) = tracked_scroll_handle.as_deref_mut() {
1567-
scroll_handle_state.overflow = style.overflow;
1568-
scroll_to_bottom = mem::take(&mut scroll_handle_state.scroll_to_bottom);
1562+
if let Some(scroll_handle) = &self.tracked_scroll_handle {
1563+
let mut state = scroll_handle.0.borrow_mut();
1564+
state.overflow = style.overflow;
1565+
scroll_to_bottom = mem::take(&mut state.scroll_to_bottom);
15691566
}
15701567

15711568
let rem_size = window.rem_size();
1572-
let padding = style.padding.to_pixels(bounds.size.into(), rem_size);
1573-
let padding_size = size(padding.left + padding.right, padding.top + padding.bottom);
1574-
let padded_content_size = self.content_size + padding_size;
1575-
let scroll_max = (padded_content_size - bounds.size).max(&Size::default());
1569+
let padding_size = size(
1570+
style
1571+
.padding
1572+
.left
1573+
.to_pixels(bounds.size.width.into(), rem_size)
1574+
+ style
1575+
.padding
1576+
.right
1577+
.to_pixels(bounds.size.width.into(), rem_size),
1578+
style
1579+
.padding
1580+
.top
1581+
.to_pixels(bounds.size.height.into(), rem_size)
1582+
+ style
1583+
.padding
1584+
.bottom
1585+
.to_pixels(bounds.size.height.into(), rem_size),
1586+
);
1587+
let scroll_max = (self.content_size + padding_size - bounds.size).max(&Size::default());
15761588
// Clamp scroll offset in case scroll max is smaller now (e.g., if children
15771589
// were removed or the bounds became larger).
15781590
let mut scroll_offset = scroll_offset.borrow_mut();
@@ -1584,10 +1596,6 @@ impl Interactivity {
15841596
scroll_offset.y = scroll_offset.y.clamp(-scroll_max.height, px(0.));
15851597
}
15861598

1587-
if let Some(mut scroll_handle_state) = tracked_scroll_handle {
1588-
scroll_handle_state.padded_content_size = padded_content_size;
1589-
}
1590-
15911599
*scroll_offset
15921600
} else {
15931601
Point::default()
@@ -2905,7 +2913,6 @@ impl ScrollAnchor {
29052913
struct ScrollHandleState {
29062914
offset: Rc<RefCell<Point<Pixels>>>,
29072915
bounds: Bounds<Pixels>,
2908-
padded_content_size: Size<Pixels>,
29092916
child_bounds: Vec<Bounds<Pixels>>,
29102917
scroll_to_bottom: bool,
29112918
overflow: Point<Overflow>,
@@ -2968,11 +2975,6 @@ impl ScrollHandle {
29682975
self.0.borrow().child_bounds.get(ix).cloned()
29692976
}
29702977

2971-
/// Get the size of the content with padding of the container.
2972-
pub fn padded_content_size(&self) -> Size<Pixels> {
2973-
self.0.borrow().padded_content_size
2974-
}
2975-
29762978
/// scroll_to_item scrolls the minimal amount to ensure that the child is
29772979
/// fully visible
29782980
pub fn scroll_to_item(&self, ix: usize) {

crates/terminal_view/src/terminal_scrollbar.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use std::{
33
rc::Rc,
44
};
55

6-
use gpui::{Bounds, Point, Size, size};
6+
use gpui::{Bounds, Point, size};
77
use terminal::Terminal;
8-
use ui::{Pixels, ScrollableHandle, px};
8+
use ui::{ContentSize, Pixels, ScrollableHandle, px};
99

1010
#[derive(Debug)]
1111
struct ScrollHandleState {
@@ -46,9 +46,12 @@ impl TerminalScrollHandle {
4646
}
4747

4848
impl ScrollableHandle for TerminalScrollHandle {
49-
fn content_size(&self) -> Size<Pixels> {
49+
fn content_size(&self) -> Option<ContentSize> {
5050
let state = self.state.borrow();
51-
size(Pixels::ZERO, state.total_lines as f32 * state.line_height)
51+
Some(ContentSize {
52+
size: size(px(0.), px(state.total_lines as f32 * state.line_height.0)),
53+
scroll_adjustment: Some(Point::new(px(0.), px(0.))),
54+
})
5255
}
5356

5457
fn offset(&self) -> Point<Pixels> {

0 commit comments

Comments
 (0)