Skip to content

Commit

Permalink
Fix selection matching against folded buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
agu-z committed Dec 29, 2024
1 parent 1f4e07f commit 3a60eca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6171,7 +6171,7 @@ impl Element for EditorElement {
Vec<Selection<Point>>,
Vec<BufferId>,
) = self.editor.update(cx, |editor, cx| {
let all_selections = editor.selections.all::<usize>(cx);
let all_selections = editor.selections.all::<Point>(cx);
let selected_buffer_ids = if editor.is_singleton(cx) {
Vec::new()
} else {
Expand All @@ -6180,7 +6180,7 @@ impl Element for EditorElement {
for selection in all_selections {
for buffer_id in snapshot
.buffer_snapshot
.buffer_ids_for_range(selection.range())
.buffer_ids_in_selected_rows(selection)
{
if selected_buffer_ids.last() != Some(&buffer_id) {
selected_buffer_ids.push(buffer_id);
Expand Down
12 changes: 5 additions & 7 deletions crates/multi_buffer/src/multi_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3449,19 +3449,17 @@ impl MultiBufferSnapshot {
}
}

pub fn buffer_ids_for_range<T: ToOffset>(
pub fn buffer_ids_in_selected_rows(
&self,
range: Range<T>,
selection: Selection<Point>,
) -> impl Iterator<Item = BufferId> + '_ {
let range = range.start.to_offset(self)..range.end.to_offset(self);

let mut cursor = self.excerpts.cursor::<(usize, Point)>(&());
cursor.seek(&range.start, Bias::Left, &());
let mut cursor = self.excerpts.cursor::<Point>(&());
cursor.seek(&Point::new(selection.start.row, 0), Bias::Right, &());
cursor.prev(&());

iter::from_fn(move || {
cursor.next(&());
if cursor.start().0 < range.end {
if cursor.start().row <= selection.end.row {
cursor.item().map(|item| item.buffer_id)
} else {
None
Expand Down

0 comments on commit 3a60eca

Please sign in to comment.