diff --git a/egui/src/widgets/text_edit/builder.rs b/egui/src/widgets/text_edit/builder.rs index bc298ffd8ec..2b29e243cd4 100644 --- a/egui/src/widgets/text_edit/builder.rs +++ b/egui/src/widgets/text_edit/builder.rs @@ -65,6 +65,7 @@ pub struct TextEdit<'t> { desired_height_rows: usize, lock_focus: bool, cursor_at_end: bool, + ignore_up_and_down_keys: bool, } impl<'t> WidgetWithState for TextEdit<'t> { @@ -111,6 +112,7 @@ impl<'t> TextEdit<'t> { desired_height_rows: 4, lock_focus: false, cursor_at_end: true, + ignore_up_and_down_keys: false, } } @@ -254,6 +256,11 @@ impl<'t> TextEdit<'t> { self.cursor_at_end = b; self } + + pub fn ignore_up_and_down_keys(mut self, ignore_up_and_down_keys: bool) -> Self { + self.ignore_up_and_down_keys = ignore_up_and_down_keys; + self + } } // ---------------------------------------------------------------------------- @@ -357,6 +364,7 @@ impl<'t> TextEdit<'t> { desired_height_rows, lock_focus, cursor_at_end, + ignore_up_and_down_keys, } = self; let text_color = text_color @@ -516,6 +524,7 @@ impl<'t> TextEdit<'t> { multiline, password, default_cursor_range, + ignore_up_and_down_keys, ); if changed { @@ -687,6 +696,7 @@ fn events( multiline: bool, password: bool, default_cursor_range: CursorRange, + ignore_up_and_down_keys: bool, ) -> (bool, CursorRange) { let mut cursor_range = state.cursor_range(&*galley).unwrap_or(default_cursor_range); @@ -799,7 +809,13 @@ fn events( key, pressed: true, modifiers, - } => on_key_press(&mut cursor_range, text, galley, *key, modifiers), + } => { + if ignore_up_and_down_keys && (*key == Key::ArrowUp || *key == Key::ArrowDown) { + None + } else { + on_key_press(&mut cursor_range, text, galley, *key, modifiers) + } + } Event::CompositionStart => { state.has_ime = true;