@@ -239,6 +239,9 @@ pub enum Direction {
Next,
}
+#[derive(Default)]
+struct ScrollbarAutoHide(bool);
+
pub fn init(cx: &mut MutableAppContext) {
cx.add_action(Editor::new_file);
cx.add_action(|this: &mut Editor, action: &Scroll, cx| this.set_scroll_position(action.0, cx));
@@ -327,6 +330,10 @@ pub fn init(cx: &mut MutableAppContext) {
cx.add_async_action(Editor::confirm_rename);
cx.add_async_action(Editor::find_all_references);
+ cx.set_global(ScrollbarAutoHide(
+ cx.platform().should_auto_hide_scrollbars(),
+ ));
+
hover_popover::init(cx);
link_go_to_definition::init(cx);
mouse_context_menu::init(cx);
@@ -5949,15 +5956,19 @@ impl Editor {
cx.notify();
}
- self.hide_scrollbar_task = Some(cx.spawn_weak(|this, mut cx| async move {
- Timer::after(SCROLLBAR_SHOW_INTERVAL).await;
- if let Some(this) = this.upgrade(&cx) {
- this.update(&mut cx, |this, cx| {
- this.show_scrollbars = false;
- cx.notify();
- });
- }
- }));
+ if cx.default_global::<ScrollbarAutoHide>().0 {
+ self.hide_scrollbar_task = Some(cx.spawn_weak(|this, mut cx| async move {
+ Timer::after(SCROLLBAR_SHOW_INTERVAL).await;
+ if let Some(this) = this.upgrade(&cx) {
+ this.update(&mut cx, |this, cx| {
+ this.show_scrollbars = false;
+ cx.notify();
+ });
+ }
+ }));
+ } else {
+ self.hide_scrollbar_task = None;
+ }
}
fn on_buffer_changed(&mut self, _: ModelHandle<MultiBuffer>, cx: &mut ViewContext<Self>) {
@@ -63,6 +63,7 @@ pub trait Platform: Send + Sync {
fn delete_credentials(&self, url: &str) -> Result<()>;
fn set_cursor_style(&self, style: CursorStyle);
+ fn should_auto_hide_scrollbars(&self) -> bool;
fn local_timezone(&self) -> UtcOffset;
@@ -699,6 +699,16 @@ impl platform::Platform for MacPlatform {
}
}
+ fn should_auto_hide_scrollbars(&self) -> bool {
+ #[allow(non_upper_case_globals)]
+ const NSScrollerStyleOverlay: NSInteger = 1;
+
+ unsafe {
+ let style: NSInteger = msg_send![class!(NSScroller), preferredScrollerStyle];
+ style == NSScrollerStyleOverlay
+ }
+ }
+
fn local_timezone(&self) -> UtcOffset {
unsafe {
let local_timezone: id = msg_send![class!(NSTimeZone), localTimeZone];