]> uap-core.de Git - note.git/commitdiff
only save notes when they were modified
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 8 Jun 2026 18:58:59 +0000 (20:58 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 8 Jun 2026 18:58:59 +0000 (20:58 +0200)
application/src/note.rs

index 6f6e59817fa2407551462ff34cdba371ddf6dec6..e168ec7124b9cf0e6c6ca5fc590928371aebdd2a 100644 (file)
@@ -26,6 +26,8 @@ pub struct Note {
     title_start: i32,
     title_end: i32,
 
+    modified: bool,
+
     #[bind("note_type")]
     pub note_type: UiInteger,
 
@@ -47,6 +49,7 @@ impl Note {
             extract_title: false,
             title_start: -1,
             title_end: -1,
+            modified: false,
 
             note_type: Default::default(),
             text: Default::default(),
@@ -126,7 +129,11 @@ impl Note {
         self.save_note();
     }
 
-    pub fn save_note(&self) {
+    pub fn save_note(&mut self) {
+        if !self.modified {
+            return;
+        }
+
         let Some(doc) = self.doc.get_doc() else {
             return;
         };
@@ -172,6 +179,8 @@ impl Note {
                 }
             });
         });
+
+        self.modified = false;
     }
 
     /// Event before the text is changed: detect if the change affects the title
@@ -203,6 +212,11 @@ impl Note {
 
     #[action]
     pub fn note_text_changed(&mut self, event: &ActionEvent) {
+        if event.set {
+            // this event was triggered by UiText.set
+            return;
+        }
+        self.modified = true;
         if !event.set && self.extract_title {
             self.update_title(self.text.get().as_str(), true);
         }