input: Fix horizontal scroll to match the longest line width. (#1238)

Close #1234
This commit is contained in:
Jason Lee 2025-09-10 18:17:15 +08:00 committed by GitHub
parent 5beaed2a9e
commit db5ba1e04c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -717,12 +717,29 @@ impl Element for TextElement {
.expect("failed to shape text");
// measure.end();
let mut max_line_width = px(0.);
let longtest_line: SharedString = state
.text
.line(state.text.summary().longest_row as usize)
.to_string()
.into();
let max_line_width = window
.text_system()
.shape_line(
longtest_line.clone(),
font_size,
&[TextRun {
len: longtest_line.len(),
font: style.font(),
color: gpui::black(),
background_color: None,
underline: None,
strikethrough: None,
}],
wrap_width,
)
.width;
let total_wrapped_lines = state.text_wrapper.len();
for line in lines.iter() {
// FIXME: The `shape_text` measured width is not stable, sometime will large, sometime small.
max_line_width = max_line_width.max(line.width());
}
let scroll_size = size(
if max_line_width + line_number_width + RIGHT_MARGIN > bounds.size.width {