multi_buffer: Fix handling of ExcerptId::max() (#38887)

This removes a hack from `MultiBuffer::anchor_at` that works around
missing logic for handling `ExcerptId::max()` by implementing that said
missing logic.

Generally, `ExcerptId::min()` is already being handled correctly due to
how `Cursor` seeking works, we tend to seek to or beyond a seek target,
meaning `min` will always match the first excerpt as expected. `max` on
the other hand will always seek beyond the last excerpt resulting in no
excerpt being found, so any code path dealing with the excerpt sumtree
will have to specially check for this special excerpt ID to work
correctly.

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Lukas Wirth
2025-10-01 07:43:22 +00:00
committed by GitHub
parent 01dbc68f82
commit fc0b249136
12 changed files with 114 additions and 164 deletions
+23 -28
View File
@@ -3211,22 +3211,27 @@ impl Editor {
let background_executor = cx.background_executor().clone();
let editor_id = cx.entity().entity_id().as_u64() as ItemId;
self.serialize_selections = cx.background_spawn(async move {
background_executor.timer(SERIALIZATION_THROTTLE_TIME).await;
let db_selections = selections
.iter()
.map(|selection| {
(
selection.start.to_offset(&snapshot),
selection.end.to_offset(&snapshot),
)
})
.collect();
background_executor.timer(SERIALIZATION_THROTTLE_TIME).await;
let db_selections = selections
.iter()
.map(|selection| {
(
selection.start.to_offset(&snapshot),
selection.end.to_offset(&snapshot),
)
})
.collect();
DB.save_editor_selections(editor_id, workspace_id, db_selections)
.await
.with_context(|| format!("persisting editor selections for editor {editor_id}, workspace {workspace_id:?}"))
.log_err();
});
DB.save_editor_selections(editor_id, workspace_id, db_selections)
.await
.with_context(|| {
format!(
"persisting editor selections for editor {editor_id}, \
workspace {workspace_id:?}"
)
})
.log_err();
});
}
}
@@ -6871,17 +6876,7 @@ impl Editor {
continue;
}
let range = Anchor {
buffer_id: Some(buffer_id),
excerpt_id,
text_anchor: start,
diff_base_anchor: None,
}..Anchor {
buffer_id: Some(buffer_id),
excerpt_id,
text_anchor: end,
diff_base_anchor: None,
};
let range = Anchor::range_in_buffer(excerpt_id, buffer_id, start..end);
if highlight.kind == lsp::DocumentHighlightKind::WRITE {
write_ranges.push(range);
} else {
@@ -12886,7 +12881,7 @@ impl Editor {
self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx);
self.change_selections(Default::default(), window, cx, |s| {
s.move_heads_with(|map, head, _| (movement::right(map, head), SelectionGoal::None));
})
});
}
pub fn move_up(&mut self, _: &MoveUp, window: &mut Window, cx: &mut Context<Self>) {
@@ -15873,7 +15868,7 @@ impl Editor {
let snapshot = multi_buffer.snapshot(cx);
if let Some(buffer_id) = snapshot.buffer_id_for_excerpt(excerpt)
&& let Some(buffer) = multi_buffer.buffer(buffer_id)
&& let Some(excerpt_range) = snapshot.buffer_range_for_excerpt(excerpt)
&& let Some(excerpt_range) = snapshot.context_range_for_excerpt(excerpt)
{
let buffer_snapshot = buffer.read(cx).snapshot();
let excerpt_end_row = Point::from_anchor(&excerpt_range.end, &buffer_snapshot).row;