Update unsaved status on undo/redo/replace/paste
Fixes: #116 Issue #116 concerns undo and redo, but I also found a few other instances where the unsaved indicator wasn't correctly updated. I fixed those as well.
This commit is contained in:
parent
59933e6a03
commit
3d4fa84759
3 changed files with 38 additions and 17 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
51
src/main.rs
51
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::<Tab>(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) => {
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue