From 571d99cecf506dff2f06809aa285318352bb65ab Mon Sep 17 00:00:00 2001 From: Anthony Eid Date: Thu, 12 Sep 2024 11:04:27 -0400 Subject: [PATCH] Fix bug where breakpoints were unable to be toggled on the first line --- crates/editor/src/editor.rs | 11 ++++++++++- crates/editor/src/element.rs | 8 +++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 46d7d86dda..5722b8233f 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -6228,6 +6228,15 @@ impl Editor { pub fn toggle_breakpoint(&mut self, _: &ToggleBreakpoint, cx: &mut ViewContext) { let cursor_position: Point = self.selections.newest(cx).head(); + // Bias is set to right when placing a breakpoint on the first row + // to avoid having the breakpoint's anchor be anchor::MIN & having + // it's buffer_id be None + let bias = if cursor_position.row == 0 { + Bias::Right + } else { + Bias::Left + }; + // We Set the column position to zero so this function interacts correctly // between calls by clicking on the gutter & using an action to toggle a // breakpoint. Otherwise, toggling a breakpoint through an action wouldn't @@ -6236,7 +6245,7 @@ impl Editor { .snapshot(cx) .display_snapshot .buffer_snapshot - .anchor_before(Point::new(cursor_position.row, 0)) + .anchor_at(Point::new(cursor_position.row, 0), bias) .text_anchor; self.toggle_breakpoint_at_anchor(breakpoint_position, cx); diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 2bc5980311..93c3cba2c2 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1610,9 +1610,15 @@ impl EditorElement { return None; } + let bias = if point.is_zero() { + Bias::Right + } else { + Bias::Left + }; + let position = snapshot .display_snapshot - .display_point_to_anchor(*point, Bias::Left) + .display_point_to_anchor(*point, bias) .text_anchor; let button = editor.render_breakpoint(position, point.row(), cx);