ViEditor: Track when changed
This commit is contained in:
parent
5352fdee94
commit
4c85a6be72
1 changed files with 18 additions and 1 deletions
|
|
@ -140,6 +140,7 @@ pub struct ViEditor<'a> {
|
||||||
passthrough: bool,
|
passthrough: bool,
|
||||||
search_opt: Option<(String, bool)>,
|
search_opt: Option<(String, bool)>,
|
||||||
commands: Commands<Change>,
|
commands: Commands<Change>,
|
||||||
|
changed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ViEditor<'a> {
|
impl<'a> ViEditor<'a> {
|
||||||
|
|
@ -150,6 +151,7 @@ impl<'a> ViEditor<'a> {
|
||||||
passthrough: false,
|
passthrough: false,
|
||||||
search_opt: None,
|
search_opt: None,
|
||||||
commands: Commands::new(),
|
commands: Commands::new(),
|
||||||
|
changed: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,6 +186,16 @@ impl<'a> ViEditor<'a> {
|
||||||
self.editor.theme()
|
self.editor.theme()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get changed flag
|
||||||
|
pub fn changed(&self) -> bool {
|
||||||
|
self.changed
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set changed flag
|
||||||
|
pub fn set_changed(&mut self, changed: bool) {
|
||||||
|
self.changed = changed;
|
||||||
|
}
|
||||||
|
|
||||||
/// Set passthrough mode (true will turn off vi features)
|
/// Set passthrough mode (true will turn off vi features)
|
||||||
pub fn set_passthrough(&mut self, passthrough: bool) {
|
pub fn set_passthrough(&mut self, passthrough: bool) {
|
||||||
if passthrough != self.passthrough {
|
if passthrough != self.passthrough {
|
||||||
|
|
@ -202,6 +214,8 @@ impl<'a> ViEditor<'a> {
|
||||||
log::info!("Redo");
|
log::info!("Redo");
|
||||||
for action in self.commands.redo() {
|
for action in self.commands.redo() {
|
||||||
undo_2_action(&mut self.editor, action);
|
undo_2_action(&mut self.editor, action);
|
||||||
|
//TODO: clear changed flag when back to last saved state?
|
||||||
|
self.changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,6 +224,8 @@ impl<'a> ViEditor<'a> {
|
||||||
log::info!("Undo");
|
log::info!("Undo");
|
||||||
for action in self.commands.undo() {
|
for action in self.commands.undo() {
|
||||||
undo_2_action(&mut self.editor, action);
|
undo_2_action(&mut self.editor, action);
|
||||||
|
//TODO: clear changed flag when back to last saved state?
|
||||||
|
self.changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -682,11 +698,12 @@ impl<'a> Edit for ViEditor<'a> {
|
||||||
|
|
||||||
self.action_inner(font_system, action);
|
self.action_inner(font_system, action);
|
||||||
|
|
||||||
|
//TODO: join changes together
|
||||||
match self.finish_change() {
|
match self.finish_change() {
|
||||||
Some(change) => {
|
Some(change) => {
|
||||||
if !change.items.is_empty() {
|
if !change.items.is_empty() {
|
||||||
log::info!("{:?}", change);
|
|
||||||
self.commands.push(change);
|
self.commands.push(change);
|
||||||
|
self.changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue