Scroll to follow expanding part of editor::SelectLargerSyntaxNode (#27295)

When the selection grows both ways, the new code prioritizes the top
part instead of bottom one, this is usually more helpful considering
that most programming language grammars tend to define tokens right
before large delimited blocks, and rarely after (because humans and
parsers read from top to bottom).

Also, revert selection when convenient, so you have more control over
what you're selecting, looking at the selection `head` is commonly more
convenient than at the `tail`.

Release Notes:

- Improve scrolling of `editor::SelectLargerSyntaxNode` for better
visibility.
This commit is contained in:
João Marcos 2025-03-22 06:06:13 -03:00 committed by GitHub
parent fa677bdc38
commit 9918b6cade
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 194 additions and 114 deletions

View file

@ -462,6 +462,28 @@ impl Editor {
self.set_scroll_position_internal(scroll_position, true, false, window, cx);
}
/// Scrolls so that `row` is at the top of the editor view.
pub fn set_scroll_top_row(
&mut self,
row: DisplayRow,
window: &mut Window,
cx: &mut Context<Editor>,
) {
let snapshot = self.snapshot(window, cx).display_snapshot;
let new_screen_top = DisplayPoint::new(row, 0);
let new_screen_top = new_screen_top.to_offset(&snapshot, Bias::Left);
let new_anchor = snapshot.buffer_snapshot.anchor_before(new_screen_top);
self.set_scroll_anchor(
ScrollAnchor {
anchor: new_anchor,
offset: Default::default(),
},
window,
cx,
);
}
pub(crate) fn set_scroll_position_internal(
&mut self,
scroll_position: gpui::Point<f32>,