Compare commits

...

1 Commits

Author SHA1 Message Date
Michael Sloan
c69e7499af Navigate to multibuffer headers (WIP)
Issue #5129
2025-02-25 13:26:56 -07:00
3 changed files with 92 additions and 0 deletions

View File

@@ -9533,6 +9533,56 @@ impl Editor {
})
}
pub fn move_to_previous_multibuffer_header(
&mut self,
_: &MoveToStartOfExcerpt,
window: &mut Window,
cx: &mut Context<Self>,
) {
if matches!(self.mode, EditorMode::SingleLine { .. }) {
cx.propagate();
return;
}
self.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
s.move_with(|map, selection| {
selection.collapse_to(
movement::multibuffer_header(
map,
selection.head(),
workspace::searchable::Direction::Prev,
),
SelectionGoal::None,
)
});
})
}
pub fn move_to_next_multibuffer_header(
&mut self,
_: &MoveToEndOfExcerpt,
window: &mut Window,
cx: &mut Context<Self>,
) {
if matches!(self.mode, EditorMode::SingleLine { .. }) {
cx.propagate();
return;
}
self.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
s.move_with(|map, selection| {
selection.collapse_to(
movement::multibuffer_header(
map,
selection.head(),
workspace::searchable::Direction::Next,
),
SelectionGoal::None,
)
});
})
}
pub fn select_to_end_of_paragraph(
&mut self,
_: &SelectToEndOfParagraph,

View File

@@ -467,6 +467,31 @@ pub fn end_of_excerpt(
}
}
pub fn multibuffer_header(
map: &DisplaySnapshot,
display_point: DisplayPoint,
direction: Direction,
) -> DisplayPoint {
let point = map.display_point_to_point(display_point, Bias::Left);
// It seems likely that the better way to implement this is to reuse block logic via
// `map.blocks_in_range` and add support for `reversed_blocks_in_range`. I haven't evaluated in
// depth whether this will work.
//
// Before thinking of that, implementation plan was to:
//
// * For `Direction::Prev`, use `reversed_excerpts_at` to iterate over the excerpts in reverse
// order.
//
// * For `Direction::Next`, use `excerpts_at` to iterate over the excerpts.
//
// * Find boundaries by checking when `buffer_id` changes similar to the block_map logic
// [here](https://github.com/zed-industries/zed/blob/e5b61949148cd87e08ae38e80949bce9b4ede9f7/crates/editor/src/display_map/block_map.rs#L845).
//
// Another alternative might be to use `excerpt_before` and `excerpt_after` methods to walk the
// excerpts.
todo!();
}
/// Scans for a boundary preceding the given start point `from` until a boundary is found,
/// indicated by the given predicate returning true.
/// The predicate is called with the character to the left and right of the candidate boundary location.

View File

@@ -4968,6 +4968,23 @@ impl MultiBufferSnapshot {
}
}
pub fn excerpts_at<T>(&self, position: T) -> impl Iterator<Item = MultiBufferExcerpt<'_>>
where
T: ToOffset,
{
todo!()
}
pub fn reversed_excerpts_at<T>(
&self,
position: T,
) -> impl Iterator<Item = MultiBufferExcerpt<'_>>
where
T: ToOffset,
{
todo!()
}
pub fn excerpt_before(&self, id: ExcerptId) -> Option<MultiBufferExcerpt<'_>> {
let start_locator = self.excerpt_locator_for_id(id);
let mut excerpts = self