summaryrefslogtreecommitdiffstats
path: root/examples/editor
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2024-09-10 16:26:15 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2024-09-10 16:26:15 +0200
commit2829c12d358b0d362cd180f83b242dcb592ca797 (patch)
treef64aec8baa245695ca89e2f0373ab5041a0cea6f /examples/editor
parent0319e160b5c66bf54f027c07b33539f3309ebef7 (diff)
downloadiced-2829c12d358b0d362cd180f83b242dcb592ca797.tar.gz
iced-2829c12d358b0d362cd180f83b242dcb592ca797.tar.bz2
iced-2829c12d358b0d362cd180f83b242dcb592ca797.zip
Use `key_binding` in `editor` example
Fixes #2573.
Diffstat (limited to 'examples/editor')
-rw-r--r--examples/editor/src/main.rs26
1 files changed, 14 insertions, 12 deletions
diff --git a/examples/editor/src/main.rs b/examples/editor/src/main.rs
index 5f12aec5..068782ba 100644
--- a/examples/editor/src/main.rs
+++ b/examples/editor/src/main.rs
@@ -4,7 +4,7 @@ use iced::widget::{
self, button, column, container, horizontal_space, pick_list, row, text,
text_editor, toggler, tooltip,
};
-use iced::{Center, Element, Fill, Font, Subscription, Task, Theme};
+use iced::{Center, Element, Fill, Font, Task, Theme};
use std::ffi;
use std::io;
@@ -13,7 +13,6 @@ use std::sync::Arc;
pub fn main() -> iced::Result {
iced::application("Editor - Iced", Editor::update, Editor::view)
- .subscription(Editor::subscription)
.theme(Editor::theme)
.font(include_bytes!("../fonts/icons.ttf").as_slice())
.default_font(Font::MONOSPACE)
@@ -137,15 +136,6 @@ impl Editor {
}
}
- fn subscription(&self) -> Subscription<Message> {
- keyboard::on_key_press(|key, modifiers| match key.as_ref() {
- keyboard::Key::Character("s") if modifiers.command() => {
- Some(Message::SaveFile)
- }
- _ => None,
- })
- }
-
fn view(&self) -> Element<Message> {
let controls = row![
action(new_icon(), "New file", Some(Message::NewFile)),
@@ -214,7 +204,19 @@ impl Editor {
.and_then(ffi::OsStr::to_str)
.unwrap_or("rs"),
self.theme,
- ),
+ )
+ .key_binding(|key_press| {
+ match key_press.key.as_ref() {
+ keyboard::Key::Character("s")
+ if key_press.modifiers.command() =>
+ {
+ Some(text_editor::Binding::Custom(
+ Message::SaveFile,
+ ))
+ }
+ _ => text_editor::Binding::from_key_press(key_press),
+ }
+ }),
status,
]
.spacing(10)