]> uap-core.de Git - note.git/commitdiff
fix note title updates using not the current note content main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 29 May 2026 16:44:55 +0000 (18:44 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 29 May 2026 16:44:55 +0000 (18:44 +0200)
application/src/note.rs
application/src/notebook.rs

index c46c776a389a2c122b903f1894806bf0b789362c..b49dbbcbd5e6c9a69b2dd1195715dfcef1203b95 100644 (file)
@@ -130,20 +130,30 @@ impl Note {
             return;
         }
 
+        let mut content = "".to_string();
         // check if any text in the title range has changed
         let pos = match &event.event_type {
-            EventType::TextInsert(t) => t.pos,
-            EventType::TextDelete(t) => t.begin,
+            EventType::TextInsert(t) => {
+                content = self.text.get();
+                content.insert_str(t.pos as usize, t.text.as_str());
+                t.pos
+            },
+            EventType::TextDelete(t) => {
+                content = self.text.get();
+                let range = t.begin as usize..t.end as usize;
+                content.replace_range(range, "");
+                t.begin
+            },
             _ => {
                 return;
             }
         };
         if self.title_end != -1 && pos > self.title_end + 1 {
-            return; // this text edit can not change the title
+            //return; // this text edit can not change the title
         }
 
         // TODO: we don't need the full text
-        self.update_title(self.text.get().as_str(), true);
+        self.update_title(content.as_str(), true);
     }
 }
 
index ad839003bd800b16f52c3c501b37055296223105..f3b9fd187227a173703c0532df5266f603c60cd7 100644 (file)
@@ -124,8 +124,8 @@ impl Notebook {
                                     if let Some(title) = &u.title {
                                         note.title = title.clone();
                                     }
+                                    update_rows.push(i);
                                 }
-                                update_rows.push(i);
                             }
                         }
                     }