From 7cc3c03b083c1d42c28f329eb6ca082712c953ab Mon Sep 17 00:00:00 2001 From: Finn Evers Date: Tue, 22 Apr 2025 00:37:04 +0200 Subject: [PATCH] editor: Fix hang when scrolling over single line input fields (#28471) Closes #21684 Closes #28463 Closes #28264 This PR fixes Zed hanging when scrolling over single line input fields with `scroll_beyond_last_line` set to `vertical_scroll_margin`. The change here is to fix the calculations of available lines. The issue only arises with the setting present because with all overscroll settings and `max_row` being 1 for single-line editors, the calculation would still return the correct value of available lines, which is 1. However, with overscrolling set to `vertical_scroll_margin` and that set to any value greater than 0, the calculation would return that the single-line editor has more than one line, which caused the issues described above (Actually, setting `vertical_scroll_margin` to 1 works for some reason, overscrolls "properly" and does not cause a crash. But I really did not want to investigate this buggy behavior further). This PR fixes this by always reporting the number of available lines as the line number value for single line editors, which will (mostly) be 1 (for more context see the discussion in this PR). Release Notes: - Fixed an issue where Zed would crash when scrolling over single line input fields and `scroll_beyond_last_line` set to `vertical_scroll_margin`. --- crates/editor/src/element.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 613232c5ca..7d53caeba9 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -6681,7 +6681,10 @@ impl Element for EditorElement { let max_row = snapshot.max_point().row().as_f32(); // The max scroll position for the top of the window - let max_scroll_top = if matches!(snapshot.mode, EditorMode::AutoHeight { .. }) { + let max_scroll_top = if matches!( + snapshot.mode, + EditorMode::AutoHeight { .. } | EditorMode::SingleLine { .. } + ) { (max_row - height_in_lines + 1.).max(0.) } else { let settings = EditorSettings::get_global(cx);