From 2fd94719e667da38c4fde3cefe5ac36a639324bd Mon Sep 17 00:00:00 2001
From: databasedav <31483365+databasedav@users.noreply.github.com>
Date: Thu, 30 May 2024 04:01:03 -0700
Subject: [PATCH] add scroll disableability (#141)

* add scroll disableability

* fmt
---
 src/cosmic_edit.rs |  4 ++++
 src/input.rs       | 50 +++++++++++++++++++++++++++-------------------
 2 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/src/cosmic_edit.rs b/src/cosmic_edit.rs
index d3f430d..0737f9b 100644
--- a/src/cosmic_edit.rs
+++ b/src/cosmic_edit.rs
@@ -70,6 +70,10 @@ pub struct MaxLines(pub usize);
 #[derive(Component, Default)]
 pub struct MaxChars(pub usize);
 
+/// Buffer does not respond to scroll events
+#[derive(Component, Default)]
+pub struct ScrollDisabled;
+
 /// A pointer to an entity with a [`CosmicEditBundle`], used to apply cosmic rendering to a UI
 /// element.
 ///
diff --git a/src/input.rs b/src/input.rs
index 8aae13b..7c4240f 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -69,6 +69,7 @@ pub(crate) fn input_mouse(
         Entity,
         &XOffset,
         &mut Sprite,
+        Option<&ScrollDisabled>,
     )>,
     node_q: Query<(&Node, &GlobalTransform, &CosmicSource)>,
     mut font_system: ResMut<CosmicFontSystem>,
@@ -107,8 +108,15 @@ pub(crate) fn input_mouse(
         return;
     };
 
-    if let Ok((mut editor, sprite_transform, text_position, entity, x_offset, sprite)) =
-        editor_q.get_mut(active_editor_entity)
+    if let Ok((
+        mut editor,
+        sprite_transform,
+        text_position,
+        entity,
+        x_offset,
+        sprite,
+        scroll_disabled,
+    )) = editor_q.get_mut(active_editor_entity)
     {
         let buffer = editor.with_buffer(|b| b.clone());
 
@@ -218,24 +226,26 @@ pub(crate) fn input_mouse(
             return;
         }
 
-        for ev in scroll_evr.read() {
-            match ev.unit {
-                MouseScrollUnit::Line => {
-                    editor.action(
-                        &mut font_system.0,
-                        Action::Scroll {
-                            lines: -ev.y as i32,
-                        },
-                    );
-                }
-                MouseScrollUnit::Pixel => {
-                    let line_height = buffer.metrics().line_height;
-                    editor.action(
-                        &mut font_system.0,
-                        Action::Scroll {
-                            lines: -(ev.y / line_height) as i32,
-                        },
-                    );
+        if scroll_disabled.is_none() {
+            for ev in scroll_evr.read() {
+                match ev.unit {
+                    MouseScrollUnit::Line => {
+                        editor.action(
+                            &mut font_system.0,
+                            Action::Scroll {
+                                lines: -ev.y as i32,
+                            },
+                        );
+                    }
+                    MouseScrollUnit::Pixel => {
+                        let line_height = buffer.metrics().line_height;
+                        editor.action(
+                            &mut font_system.0,
+                            Action::Scroll {
+                                lines: -(ev.y / line_height) as i32,
+                            },
+                        );
+                    }
                 }
             }
         }
-- 
GitLab