Skip to content

Commit

Permalink
Save file on Cmd+S in editor example
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Sep 19, 2023
1 parent 06dc12b commit c0a141a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion examples/editor/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use iced::executor;
use iced::keyboard;
use iced::theme::{self, Theme};
use iced::widget::{
button, column, container, horizontal_space, pick_list, row, text,
text_editor, tooltip,
};
use iced::{Alignment, Application, Command, Element, Font, Length, Settings};
use iced::{
Alignment, Application, Command, Element, Font, Length, Settings,
Subscription,
};

use highlighter::Highlighter;

Expand Down Expand Up @@ -147,6 +151,15 @@ impl Application for Editor {
}
}

fn subscription(&self) -> Subscription<Message> {
keyboard::on_key_press(|key_code, modifiers| match key_code {
keyboard::KeyCode::S if modifiers.command() => {
Some(Message::SaveFile)
}
_ => None,
})
}

fn view(&self) -> Element<Message> {
let controls = row![
action(new_icon(), "New file", Some(Message::NewFile)),
Expand Down

0 comments on commit c0a141a

Please sign in to comment.