diff --git a/src/cosmic_edit.rs b/src/cosmic_edit.rs index d3f430d3266fb2191ab6c216d56a0f14c42e055b..0737f9b47042283ecb3bb32495bcf6aa1c009d4b 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 8aae13b76cda14769991d5cf658fc0796e2e7543..7c4240f0411bda06f6cbbd69745812df14fa5502 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, + }, + ); + } } } }