Skip to content

Commit

Permalink
Fix toggle breakpoints having a max of one bp per buffer
Browse files Browse the repository at this point in the history
Breakpoints are now stored in a BTreeMap<buffer_id, HashSet<Breakpoint>>
I did this becauase we need to constant check if a breakpoint exists in
a buffer whenever we toggle one.
  • Loading branch information
Anthony-Eid committed Jul 25, 2024
1 parent d485745 commit 7dce8d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
20 changes: 10 additions & 10 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ struct ResolvedTasks {
position: Anchor,
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
struct Breakpoint {
position: Anchor,
}
Expand Down Expand Up @@ -574,7 +574,7 @@ pub struct Editor {
expect_bounds_change: Option<Bounds<Pixels>>,
tasks: BTreeMap<(BufferId, BufferRow), RunnableTasks>,
tasks_update_task: Option<Task<()>>,
breakpoints: BTreeMap<(BufferId, ExcerptId), Breakpoint>,
breakpoints: BTreeMap<BufferId, HashSet<Breakpoint>>,
previous_search_ranges: Option<Arc<[Range<Anchor>]>>,
file_header_size: u8,
breadcrumb_header: Option<String>,
Expand Down Expand Up @@ -5999,15 +5999,15 @@ impl Editor {
};

let buffer_id = buffer.read(cx).remote_id();
let key = (buffer_id, breakpoint_position.excerpt_id);
// let key = (buffer_id, breakpoint_position);
let breakpoint = Breakpoint {
position: breakpoint_position,
};

if self.breakpoints.remove(&key).is_none() {
self.breakpoints.insert(
key,
Breakpoint {
position: breakpoint_position,
},
);
let breakpoint_set = self.breakpoints.entry(buffer_id).or_default();

if !breakpoint_set.remove(&breakpoint) {
breakpoint_set.insert(breakpoint);
}
// let row = breakpoint_position
// .to_point(&(self.snapshot(cx).display_snapshot.buffer_snapshot))
Expand Down
3 changes: 2 additions & 1 deletion crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,8 @@ impl EditorElement {
editor
.breakpoints
.iter()
.filter_map(|(_, breakpoint)| {
.flat_map(|(_buffer_id, breakpoint_set)| breakpoint_set.iter())
.filter_map(|breakpoint| {
let point = breakpoint
.position
.to_display_point(&snapshot.display_snapshot);
Expand Down

0 comments on commit 7dce8d5

Please sign in to comment.