diff --git a/Cargo.lock b/Cargo.lock index d1697d2..8700f91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1161,7 +1161,7 @@ dependencies = [ [[package]] name = "cosmic-text" version = "0.11.2" -source = "git+https://github.com/pop-os/cosmic-text.git#b08676909f882f553ab574601b35b58276a52458" +source = "git+https://github.com/pop-os/cosmic-text.git#ff5501d9a36e51c50d908413caf7632d8f7533b7" dependencies = [ "bitflags 2.4.2", "cosmic_undo_2", diff --git a/src/main.rs b/src/main.rs index f354c4a..0a9c079 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1487,13 +1487,19 @@ impl Application for App { } Message::Cut => { if let Some(Tab::Editor(tab)) = self.active_tab() { - let mut editor = tab.editor.lock().unwrap(); - let selection_opt = editor.copy_selection(); - editor.start_change(); - editor.delete_selection(); - editor.finish_change(); + let selection_opt = { + let mut editor = tab.editor.lock().unwrap(); + let selection_opt = editor.copy_selection(); + editor.start_change(); + editor.delete_selection(); + editor.finish_change(); + selection_opt + }; if let Some(selection) = selection_opt { - return clipboard::write(selection); + return Command::batch([ + clipboard::write(selection), + self.update(Message::TabChanged(self.tab_model.active())), + ]); } } } @@ -1616,6 +1622,7 @@ impl Application for App { Ok(regex) => { //TODO: support captures tab.replace(®ex, &self.find_replace_value); + return self.update(Message::TabChanged(self.tab_model.active())); } Err(err) => { //TODO: put regex error in find box @@ -1644,6 +1651,7 @@ impl Application for App { editor.set_cursor(cosmic_text::Cursor::new(0, 0)); } while tab.replace(®ex, &self.find_replace_value) {} + return self.update(Message::TabChanged(self.tab_model.active())); } Err(err) => { //TODO: put regex error in find box @@ -1892,10 +1900,13 @@ impl Application for App { } Message::PasteValue(value) => { if let Some(Tab::Editor(tab)) = self.active_tab() { - let mut editor = tab.editor.lock().unwrap(); - editor.start_change(); - editor.insert_string(&value, None); - editor.finish_change(); + { + let mut editor = tab.editor.lock().unwrap(); + editor.start_change(); + editor.insert_string(&value, None); + editor.finish_change(); + } + return self.update(Message::TabChanged(self.tab_model.active())); } } Message::PrepareGitDiff(project_path, path, staged) => { @@ -1974,8 +1985,12 @@ impl Application for App { } Message::Redo => { if let Some(Tab::Editor(tab)) = self.active_tab() { - let mut editor = tab.editor.lock().unwrap(); - editor.redo(); + { + let mut editor = tab.editor.lock().unwrap(); + editor.redo(); + } + + return self.update(Message::TabChanged(self.tab_model.active())); } } Message::Save => { @@ -2096,7 +2111,9 @@ impl Application for App { if let Some(Tab::Editor(tab)) = self.tab_model.data::(entity) { let mut title = tab.title(); //TODO: better way of adding change indicator - title.push_str(" \u{2022}"); + if tab.changed() { + title.push_str(" \u{2022}"); + } self.tab_model.text_set(entity, title); } } @@ -2316,8 +2333,12 @@ impl Application for App { } Message::Undo => { if let Some(Tab::Editor(tab)) = self.active_tab() { - let mut editor = tab.editor.lock().unwrap(); - editor.undo(); + { + let mut editor = tab.editor.lock().unwrap(); + editor.undo(); + } + + return self.update(Message::TabChanged(self.tab_model.active())); } } Message::VimBindings(vim_bindings) => { diff --git a/src/tab.rs b/src/tab.rs index ec155e5..3f9035b 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -152,7 +152,7 @@ impl EditorTab { }); match fs::write(path, text) { Ok(()) => { - editor.set_changed(false); + editor.save_point(); log::info!("saved {:?}", path); } Err(err) => {