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:
parent
fa677bdc38
commit
9918b6cade
5 changed files with 194 additions and 114 deletions
|
@ -38,6 +38,16 @@ impl Autoscroll {
|
|||
Self::Strategy(AutoscrollStrategy::TopRelative(n))
|
||||
}
|
||||
|
||||
/// Scrolls so that the newest cursor is at the top.
|
||||
pub fn top() -> Self {
|
||||
Self::Strategy(AutoscrollStrategy::Top)
|
||||
}
|
||||
|
||||
/// Scrolls so that the newest cursor is roughly an n-th line from the bottom.
|
||||
pub fn bottom_relative(n: usize) -> Self {
|
||||
Self::Strategy(AutoscrollStrategy::BottomRelative(n))
|
||||
}
|
||||
|
||||
/// Scrolls so that the newest cursor is at the bottom.
|
||||
pub fn bottom() -> Self {
|
||||
Self::Strategy(AutoscrollStrategy::Bottom)
|
||||
|
@ -54,6 +64,7 @@ pub enum AutoscrollStrategy {
|
|||
Top,
|
||||
Bottom,
|
||||
TopRelative(usize),
|
||||
BottomRelative(usize),
|
||||
}
|
||||
|
||||
impl AutoscrollStrategy {
|
||||
|
@ -213,6 +224,10 @@ impl Editor {
|
|||
scroll_position.y = target_top - lines as f32;
|
||||
self.set_scroll_position_internal(scroll_position, local, true, window, cx);
|
||||
}
|
||||
AutoscrollStrategy::BottomRelative(lines) => {
|
||||
scroll_position.y = target_bottom + lines as f32;
|
||||
self.set_scroll_position_internal(scroll_position, local, true, window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
self.scroll_manager.last_autoscroll = Some((
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue