Allow to cycle through center/top/bot scroll positions (#16134)

On top of `editor::ScrollCursorCenter`, `editor::ScrollCursorTop`,
`editor::ScrollCursorBottom` actions, adds an
`editor::ScrollCursorCenterTopBottom` one, that allows using a single
keybinding to scroll between positions on the screen.

The implementation matches a corresponding Emacs feature: there's a
timeout (1s) that is kept after every switch, to allow continuously
changing the positions, center (initial) -> top -> bottom
Scrolling behavior is the same as the existing actions (e.g. editor will
ignore scroll to bottom, if there's not enough space above).

After 1s, next position is reset to the initial, center, one.


Release Notes:

- Added an `editor::ScrollCursorCenterTopBottom` action for toggling
scroll position with a single keybinding

---------

Co-authored-by: Alex Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
Kirill Bulatov
2024-08-13 00:32:30 +03:00
committed by GitHub
co-authored by Alex Kladov
parent 98516b5527
commit 3bebb8b401
5 changed files with 153 additions and 2 deletions
+23
View File
@@ -175,6 +175,7 @@ pub const CODE_ACTIONS_DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(250);
pub const DOCUMENT_HIGHLIGHTS_DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(75);
pub(crate) const FORMAT_TIMEOUT: Duration = Duration::from_secs(2);
pub(crate) const SCROLL_CENTER_TOP_BOTTOM_DEBOUNCE_TIMEOUT: Duration = Duration::from_secs(1);
pub fn render_parsed_markdown(
element_id: impl Into<ElementId>,
@@ -561,6 +562,26 @@ pub struct Editor {
file_header_size: u32,
breadcrumb_header: Option<String>,
focused_block: Option<FocusedBlock>,
next_scroll_position: NextScrollCursorCenterTopBottom,
_scroll_cursor_center_top_bottom_task: Task<()>,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
enum NextScrollCursorCenterTopBottom {
#[default]
Center,
Top,
Bottom,
}
impl NextScrollCursorCenterTopBottom {
fn next(&self) -> Self {
match self {
Self::Center => Self::Top,
Self::Top => Self::Bottom,
Self::Bottom => Self::Center,
}
}
}
#[derive(Clone)]
@@ -1895,6 +1916,8 @@ impl Editor {
previous_search_ranges: None,
breadcrumb_header: None,
focused_block: None,
next_scroll_position: NextScrollCursorCenterTopBottom::default(),
_scroll_cursor_center_top_bottom_task: Task::ready(()),
};
this.tasks_update_task = Some(this.refresh_runnables(cx));
this._subscriptions.extend(project_subscriptions);