Undo/redo support
This commit is contained in:
parent
f76f83565c
commit
c84a256376
4 changed files with 63 additions and 4 deletions
|
|
@ -23,10 +23,12 @@ pub enum Action {
|
|||
OpenProjectDialog,
|
||||
Paste,
|
||||
Quit,
|
||||
Redo,
|
||||
Save,
|
||||
SelectAll,
|
||||
ToggleSettingsPage,
|
||||
ToggleWordWrap,
|
||||
Undo,
|
||||
}
|
||||
|
||||
impl Action {
|
||||
|
|
@ -42,10 +44,12 @@ impl Action {
|
|||
Self::OpenProjectDialog => Message::OpenProjectDialog,
|
||||
Self::Paste => Message::Paste,
|
||||
Self::Quit => Message::Quit,
|
||||
Self::Redo => Message::Redo,
|
||||
Self::Save => Message::Save,
|
||||
Self::SelectAll => Message::SelectAll,
|
||||
Self::ToggleSettingsPage => Message::ToggleContextPage(ContextPage::Settings),
|
||||
Self::ToggleWordWrap => Message::ToggleWordWrap,
|
||||
Self::Undo => Message::Undo,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -107,10 +111,12 @@ impl KeyBind {
|
|||
bind!([Ctrl], O, OpenFileDialog);
|
||||
bind!([Ctrl, Shift], O, OpenProjectDialog);
|
||||
bind!([Ctrl], Q, Quit);
|
||||
bind!([Ctrl, Shift], Z, Redo);
|
||||
bind!([Ctrl], S, Save);
|
||||
bind!([Ctrl], A, SelectAll);
|
||||
bind!([Ctrl], Comma, ToggleSettingsPage);
|
||||
bind!([Alt], Z, ToggleWordWrap);
|
||||
bind!([Ctrl], Z, Undo);
|
||||
|
||||
keybinds
|
||||
}
|
||||
|
|
|
|||
16
src/main.rs
16
src/main.rs
|
|
@ -120,6 +120,7 @@ pub enum Message {
|
|||
Paste,
|
||||
PasteValue(String),
|
||||
Quit,
|
||||
Redo,
|
||||
Save,
|
||||
SelectAll,
|
||||
SyntaxTheme(usize, bool),
|
||||
|
|
@ -128,6 +129,7 @@ pub enum Message {
|
|||
Todo,
|
||||
ToggleContextPage(ContextPage),
|
||||
ToggleWordWrap,
|
||||
Undo,
|
||||
VimBindings(bool),
|
||||
}
|
||||
|
||||
|
|
@ -689,6 +691,13 @@ impl Application for App {
|
|||
//TODO: prompt for save?
|
||||
return window::close();
|
||||
}
|
||||
Message::Redo => match self.active_tab() {
|
||||
Some(tab) => {
|
||||
let mut editor = tab.editor.lock().unwrap();
|
||||
editor.redo();
|
||||
}
|
||||
None => {}
|
||||
},
|
||||
Message::Save => {
|
||||
let mut title_opt = None;
|
||||
|
||||
|
|
@ -785,6 +794,13 @@ impl Application for App {
|
|||
self.config.word_wrap = !self.config.word_wrap;
|
||||
return self.save_config();
|
||||
}
|
||||
Message::Undo => match self.active_tab() {
|
||||
Some(tab) => {
|
||||
let mut editor = tab.editor.lock().unwrap();
|
||||
editor.undo();
|
||||
}
|
||||
None => {}
|
||||
},
|
||||
Message::VimBindings(vim_bindings) => {
|
||||
self.config.vim_bindings = vim_bindings;
|
||||
return self.save_config();
|
||||
|
|
|
|||
|
|
@ -132,8 +132,8 @@ pub fn menu_bar<'a>(config: &Config) -> Element<'a, Message> {
|
|||
MenuTree::with_children(
|
||||
menu_root(fl!("edit")),
|
||||
vec![
|
||||
menu_key(fl!("undo"), "Ctrl + Z", Message::Todo),
|
||||
menu_key(fl!("redo"), "Ctrl + Shift + Z", Message::Todo),
|
||||
menu_item(fl!("undo"), Message::Undo),
|
||||
menu_item(fl!("redo"), Message::Redo),
|
||||
MenuTree::new(horizontal_rule(1)),
|
||||
menu_item(fl!("cut"), Message::Cut),
|
||||
menu_item(fl!("copy"), Message::Copy),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue