mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-20 02:47:34 +03:00
Fix cursor adjustment on scroll
Fixes: zed-industries/community#1929 Also preserves visual modes correctly.
This commit is contained in:
parent
d1aa82bb48
commit
e3c0e93e46
@ -29,6 +29,7 @@ use self::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub const SCROLL_EVENT_SEPARATION: Duration = Duration::from_millis(28);
|
pub const SCROLL_EVENT_SEPARATION: Duration = Duration::from_millis(28);
|
||||||
|
pub const VERTICAL_SCROLL_MARGIN: f32 = 3.;
|
||||||
const SCROLLBAR_SHOW_INTERVAL: Duration = Duration::from_secs(1);
|
const SCROLLBAR_SHOW_INTERVAL: Duration = Duration::from_secs(1);
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@ -136,7 +137,7 @@ pub struct ScrollManager {
|
|||||||
impl ScrollManager {
|
impl ScrollManager {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
ScrollManager {
|
ScrollManager {
|
||||||
vertical_scroll_margin: 3.0,
|
vertical_scroll_margin: VERTICAL_SCROLL_MARGIN,
|
||||||
anchor: ScrollAnchor::new(),
|
anchor: ScrollAnchor::new(),
|
||||||
ongoing: OngoingScroll::new(),
|
ongoing: OngoingScroll::new(),
|
||||||
autoscroll_request: None,
|
autoscroll_request: None,
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
use std::cmp::Ordering;
|
|
||||||
|
|
||||||
use crate::Vim;
|
use crate::Vim;
|
||||||
use editor::{display_map::ToDisplayPoint, scroll::scroll_amount::ScrollAmount, Editor};
|
use editor::{
|
||||||
|
display_map::ToDisplayPoint,
|
||||||
|
scroll::{scroll_amount::ScrollAmount, VERTICAL_SCROLL_MARGIN},
|
||||||
|
DisplayPoint, Editor,
|
||||||
|
};
|
||||||
use gpui::{actions, AppContext, ViewContext};
|
use gpui::{actions, AppContext, ViewContext};
|
||||||
use language::Bias;
|
use language::Bias;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
@ -53,13 +55,9 @@ fn scroll(cx: &mut ViewContext<Workspace>, by: fn(c: Option<f32>) -> ScrollAmoun
|
|||||||
|
|
||||||
fn scroll_editor(editor: &mut Editor, amount: &ScrollAmount, cx: &mut ViewContext<Editor>) {
|
fn scroll_editor(editor: &mut Editor, amount: &ScrollAmount, cx: &mut ViewContext<Editor>) {
|
||||||
let should_move_cursor = editor.newest_selection_on_screen(cx).is_eq();
|
let should_move_cursor = editor.newest_selection_on_screen(cx).is_eq();
|
||||||
|
|
||||||
editor.scroll_screen(amount, cx);
|
editor.scroll_screen(amount, cx);
|
||||||
if should_move_cursor {
|
if should_move_cursor {
|
||||||
let selection_ordering = editor.newest_selection_on_screen(cx);
|
|
||||||
if selection_ordering.is_eq() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let visible_rows = if let Some(visible_rows) = editor.visible_line_count() {
|
let visible_rows = if let Some(visible_rows) = editor.visible_line_count() {
|
||||||
visible_rows as u32
|
visible_rows as u32
|
||||||
} else {
|
} else {
|
||||||
@ -69,21 +67,19 @@ fn scroll_editor(editor: &mut Editor, amount: &ScrollAmount, cx: &mut ViewContex
|
|||||||
let top_anchor = editor.scroll_manager.anchor().anchor;
|
let top_anchor = editor.scroll_manager.anchor().anchor;
|
||||||
|
|
||||||
editor.change_selections(None, cx, |s| {
|
editor.change_selections(None, cx, |s| {
|
||||||
s.replace_cursors_with(|snapshot| {
|
s.move_heads_with(|map, head, goal| {
|
||||||
let mut new_point = top_anchor.to_display_point(&snapshot);
|
let top = top_anchor.to_display_point(map);
|
||||||
|
let min_row = top.row() + VERTICAL_SCROLL_MARGIN as u32;
|
||||||
|
let max_row = top.row() + visible_rows - VERTICAL_SCROLL_MARGIN as u32 - 1;
|
||||||
|
|
||||||
match selection_ordering {
|
let new_head = if head.row() < min_row {
|
||||||
Ordering::Less => {
|
map.clip_point(DisplayPoint::new(min_row, head.column()), Bias::Left)
|
||||||
new_point = snapshot.clip_point(new_point, Bias::Right);
|
} else if head.row() > max_row {
|
||||||
}
|
map.clip_point(DisplayPoint::new(max_row, head.column()), Bias::Left)
|
||||||
Ordering::Greater => {
|
} else {
|
||||||
*new_point.row_mut() += visible_rows - 1;
|
head
|
||||||
new_point = snapshot.clip_point(new_point, Bias::Left);
|
};
|
||||||
}
|
(new_head, goal)
|
||||||
Ordering::Equal => unreachable!(),
|
|
||||||
}
|
|
||||||
|
|
||||||
vec![new_point]
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user