From 8052cf8415e9352ad477040b75eb20440ace7597 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 23:41:03 +0100 Subject: [PATCH] editor: Adjust offset of the opened jump target in the multibuffer (cherry-pick #23091) (#23101) Cherry-picked editor: Adjust offset of the opened jump target in the multibuffer (#23091) This PR fixes an issue with jumping from multi_buffer to a file; namely, the scroll offset of the opened buffer used to match the position within the multibuffer, but it broke a while back. This is because we were opening a buffer without providing the data about the origin scroll offset. Closes #ISSUE Release Notes: - Fixed a bug where the relative position of an excerpt within the multibuffer was not accounted for while jumping to the buffer, causing the clicked line to drastically change position on screen. Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> --- crates/editor/src/element.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 509ea6bf4facdf45428f8ea1d9af2aefd2def9e4..112b65f8fe2086356b632e7483ea34cf76f2d8f0 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -543,8 +543,29 @@ impl EditorElement { // and run the selection logic. modifiers.alt = false; } else { + let scroll_position_row = + position_map.scroll_pixel_position.y / position_map.line_height; + let display_row = (((event.position - gutter_hitbox.bounds.origin).y + + position_map.scroll_pixel_position.y) + / position_map.line_height) + as u32; + let multi_buffer_row = position_map + .snapshot + .display_point_to_point( + DisplayPoint::new(DisplayRow(display_row), 0), + Bias::Right, + ) + .row; + let line_offset_from_top = display_row - scroll_position_row as u32; // if double click is made without alt, open the corresponding excerp - editor.open_excerpts(&OpenExcerpts, cx); + editor.open_excerpts_common( + Some(JumpData::MultiBufferRow { + row: MultiBufferRow(multi_buffer_row), + line_offset_from_top, + }), + false, + cx, + ); return; } }