From 32a95171d2c2a7a7ac8c141277b8c3555dbb3e77 Mon Sep 17 00:00:00 2001 From: Casper Rogild Storm Date: Mon, 31 Jul 2023 22:59:42 +0200 Subject: [PATCH 1/3] cycle combobox with keybinds --- widget/src/combo_box.rs | 43 ++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/widget/src/combo_box.rs b/widget/src/combo_box.rs index 93fc92b98f..c9397433e3 100644 --- a/widget/src/combo_box.rs +++ b/widget/src/combo_box.rs @@ -468,11 +468,13 @@ where if let Event::Keyboard(keyboard::Event::KeyPressed { key_code, + modifiers, .. }) = event { - match key_code { - keyboard::KeyCode::Enter => { + let shift_modifer = modifiers.shift(); + match (key_code, shift_modifer) { + (keyboard::KeyCode::Enter, _) => { if let Some(index) = &menu.hovered_option { if let Some(option) = state.filtered_options.options.get(*index) @@ -483,9 +485,19 @@ where event_status = event::Status::Captured; } - keyboard::KeyCode::Up => { + + (keyboard::KeyCode::Up, _) + | (keyboard::KeyCode::Tab, true) => { if let Some(index) = &mut menu.hovered_option { - *index = index.saturating_sub(1); + if *index == 0 { + *index = state + .filtered_options + .options + .len() + .saturating_sub(1); + } else { + *index = index.saturating_sub(1); + } } else { menu.hovered_option = Some(0); } @@ -511,15 +523,28 @@ where event_status = event::Status::Captured; } - keyboard::KeyCode::Down => { + (keyboard::KeyCode::Down, _) + | (keyboard::KeyCode::Tab, false) + if !modifiers.shift() => + { if let Some(index) = &mut menu.hovered_option { - *index = index.saturating_add(1).min( - state + if *index + == state .filtered_options .options .len() - .saturating_sub(1), - ); + .saturating_sub(1) + { + *index = 0; + } else { + *index = index.saturating_add(1).min( + state + .filtered_options + .options + .len() + .saturating_sub(1), + ); + } } else { menu.hovered_option = Some(0); } From e1da5fa63525cf749ec5ebbef42703fb761a0dd1 Mon Sep 17 00:00:00 2001 From: Casper Rogild Storm Date: Mon, 31 Jul 2023 23:07:35 +0200 Subject: [PATCH 2/3] Update widget/src/combo_box.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Héctor Ramón --- widget/src/combo_box.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widget/src/combo_box.rs b/widget/src/combo_box.rs index c9397433e3..5e36ec5705 100644 --- a/widget/src/combo_box.rs +++ b/widget/src/combo_box.rs @@ -529,7 +529,7 @@ where { if let Some(index) = &mut menu.hovered_option { if *index - == state + >= state .filtered_options .options .len() From 983764db6a65cad673d35d3112145a8e40e82be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 2 Aug 2023 22:22:51 +0200 Subject: [PATCH 3/3] Update `CHANGELOG` --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ab7b247f0..f7e600307f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Nix instructions to `DEPENDENCIES.md`. [#1859](https://github.com/iced-rs/iced/pull/1859) - Loading spinners example. [#1902](https://github.com/iced-rs/iced/pull/1902) - Workflow that verifies `CHANGELOG` is always up-to-date. [#1970](https://github.com/iced-rs/iced/pull/1970) +- Keybinds to cycle `ComboBox` options. [#1991](https://github.com/iced-rs/iced/pull/1991) ### Changed - Updated `wgpu` to `0.16`. [#1807](https://github.com/iced-rs/iced/pull/1807)