Skip to content

Commit

Permalink
https://github.com/emilk/egui/pull/777
Browse files Browse the repository at this point in the history
  • Loading branch information
Titaniumtown committed Apr 4, 2022
1 parent b659a6b commit 1be4296
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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
}
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -516,6 +524,7 @@ impl<'t> TextEdit<'t> {
multiline,
password,
default_cursor_range,
ignore_up_and_down_keys,
);

if changed {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1be4296

Please sign in to comment.