editor: Toggle diff hunk based on current mouse position (#40773)
This fixes an issue where we would search for the hovered diff hunk based on the mouse hit test computed during (or prior) editor paint instead of the mouse hit test computed prior to the mouse event invocation. That in turn could lead to cases where moving the mouse from the editor to the project panel and then clicking a file shortly after would expand a diff hunk when actually nothing should happen in that case. Release Notes: - Fixed an issue where diff hunks would sometimes erroneously toggle upon mouse clicks.
This commit is contained in:
@@ -652,7 +652,6 @@ impl EditorElement {
|
||||
fn mouse_left_down(
|
||||
editor: &mut Editor,
|
||||
event: &MouseDownEvent,
|
||||
hovered_hunk: Option<Range<Anchor>>,
|
||||
position_map: &PositionMap,
|
||||
line_numbers: &HashMap<MultiBufferRow, LineNumberLayout>,
|
||||
window: &mut Window,
|
||||
@@ -668,7 +667,20 @@ impl EditorElement {
|
||||
let mut click_count = event.click_count;
|
||||
let mut modifiers = event.modifiers;
|
||||
|
||||
if let Some(hovered_hunk) = hovered_hunk {
|
||||
if let Some(hovered_hunk) =
|
||||
position_map
|
||||
.display_hunks
|
||||
.iter()
|
||||
.find_map(|(hunk, hunk_hitbox)| match hunk {
|
||||
DisplayDiffHunk::Folded { .. } => None,
|
||||
DisplayDiffHunk::Unfolded {
|
||||
multi_buffer_range, ..
|
||||
} => hunk_hitbox
|
||||
.as_ref()
|
||||
.is_some_and(|hitbox| hitbox.is_hovered(window))
|
||||
.then(|| multi_buffer_range.clone()),
|
||||
})
|
||||
{
|
||||
editor.toggle_single_diff_hunk(hovered_hunk, cx);
|
||||
cx.notify();
|
||||
return;
|
||||
@@ -7263,26 +7275,6 @@ impl EditorElement {
|
||||
window.on_mouse_event({
|
||||
let position_map = layout.position_map.clone();
|
||||
let editor = self.editor.clone();
|
||||
let diff_hunk_range =
|
||||
layout
|
||||
.display_hunks
|
||||
.iter()
|
||||
.find_map(|(hunk, hunk_hitbox)| match hunk {
|
||||
DisplayDiffHunk::Folded { .. } => None,
|
||||
DisplayDiffHunk::Unfolded {
|
||||
multi_buffer_range, ..
|
||||
} => {
|
||||
if hunk_hitbox
|
||||
.as_ref()
|
||||
.map(|hitbox| hitbox.is_hovered(window))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
Some(multi_buffer_range.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
});
|
||||
let line_numbers = layout.line_numbers.clone();
|
||||
|
||||
move |event: &MouseDownEvent, phase, window, cx| {
|
||||
@@ -7299,7 +7291,6 @@ impl EditorElement {
|
||||
Self::mouse_left_down(
|
||||
editor,
|
||||
event,
|
||||
diff_hunk_range.clone(),
|
||||
&position_map,
|
||||
line_numbers.as_ref(),
|
||||
window,
|
||||
|
||||
Reference in New Issue
Block a user