Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

editor: Un-pub `ScrollManager` (#55767)

Finn Eversa2cd962a1ab0
diff --git a/crates/agent_ui/src/entry_view_state.rs b/crates/agent_ui/src/entry_view_state.rs
index 853672142fb..15bd9e89b57 100644
--- a/crates/agent_ui/src/entry_view_state.rs
+++ b/crates/agent_ui/src/entry_view_state.rs
@@ -449,7 +449,7 @@ fn create_editor_diff(
editor.set_show_vertical_scrollbar(false, cx);
editor.set_minimap_visibility(MinimapVisibility::Disabled, window, cx);
editor.set_soft_wrap_mode(SoftWrap::None, cx);
- editor.scroll_manager.set_forbid_vertical_scroll(true);
+ editor.set_forbid_vertical_scroll(true);
editor.set_show_indent_guides(false, cx);
editor.set_read_only(true);
editor.set_delegate_open_excerpts(true);
diff --git a/crates/agent_ui/src/inline_assistant.rs b/crates/agent_ui/src/inline_assistant.rs
index cdff9785df7..d442a61e01a 100644
--- a/crates/agent_ui/src/inline_assistant.rs
+++ b/crates/agent_ui/src/inline_assistant.rs
@@ -1425,7 +1425,7 @@ impl InlineAssistant {
editor.set_show_gutter(false, cx);
editor.set_offset_content(false, cx);
editor.disable_mouse_wheel_zoom();
- editor.scroll_manager.set_forbid_vertical_scroll(true);
+ editor.set_forbid_vertical_scroll(true);
editor.set_read_only(true);
editor.set_show_edit_predictions(Some(false), window, cx);
editor.highlight_rows::<DeletedLines>(
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index af8d6f6ccc6..d9dd6078c08 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -1157,7 +1157,12 @@ pub struct Editor {
pub display_map: Entity<DisplayMap>,
placeholder_display_map: Option<Entity<DisplayMap>>,
pub selections: SelectionsCollection,
- pub scroll_manager: ScrollManager,
+ /// Manages the scroll position for the given editor.
+ ///
+ /// Whenever you want to modify the scroll position of the editor, you should
+ /// usually use the existing available APIs as opposed to directly interacting
+ /// with the scroll manager.
+ pub(crate) scroll_manager: ScrollManager,
/// When inline assist editors are linked, they all render cursors because
/// typing enters text into each of them, even the ones that aren't focused.
pub(crate) show_cursor_when_unfocused: bool,
diff --git a/crates/editor/src/scroll.rs b/crates/editor/src/scroll.rs
index 143a73fd701..f067519e734 100644
--- a/crates/editor/src/scroll.rs
+++ b/crates/editor/src/scroll.rs
@@ -623,6 +623,14 @@ impl Editor {
self.scroll_manager.has_autoscroll_request()
}
+ pub fn set_forbid_vertical_scroll(&mut self, forbid: bool) {
+ self.scroll_manager.set_forbid_vertical_scroll(forbid);
+ }
+
+ pub fn scroll_top_display_point(&self, snapshot: &DisplaySnapshot, cx: &App) -> DisplayPoint {
+ self.scroll_manager.scroll_top_display_point(snapshot, cx)
+ }
+
pub fn vertical_scroll_margin(&self) -> usize {
self.scroll_manager.vertical_scroll_margin as usize
}
diff --git a/crates/vim/src/normal/scroll.rs b/crates/vim/src/normal/scroll.rs
index 01719cd5932..befaacf31c7 100644
--- a/crates/vim/src/normal/scroll.rs
+++ b/crates/vim/src/normal/scroll.rs
@@ -109,9 +109,7 @@ impl Vim {
self.update_editor(cx, |vim, editor, cx| {
let should_move_cursor = editor.newest_selection_on_screen(cx).is_eq();
let display_snapshot = editor.display_map.update(cx, |map, cx| map.snapshot(cx));
- let old_top = editor
- .scroll_manager
- .scroll_top_display_point(&display_snapshot, cx);
+ let old_top = editor.scroll_top_display_point(&display_snapshot, cx);
if editor.scroll_hover(amount, window, cx) {
return;
@@ -143,9 +141,7 @@ impl Vim {
};
let display_snapshot = editor.display_map.update(cx, |map, cx| map.snapshot(cx));
- let top = editor
- .scroll_manager
- .scroll_top_display_point(&display_snapshot, cx);
+ let top = editor.scroll_top_display_point(&display_snapshot, cx);
let vertical_scroll_margin = EditorSettings::get_global(cx).vertical_scroll_margin;
let mut move_cursor = |map: &editor::display_map::DisplaySnapshot,