| ... | ... | @@ -349,7 +349,9 @@ struct Site { |
| 349 | 349 | /// path. |
| 350 | 350 | held: Vec<(String, Arc<Replica>)>, |
| 351 | 351 | author: String, |
| 352 | | fresh: PageCreation, |
| 352 | /// The page a section left without pages gains; none in the recycle bin, which OneNote |
| 353 | /// leaves empty. |
| 354 | fresh: Option<PageCreation>, |
| 353 | 355 | } |
| 354 | 356 | |
| 355 | 357 | /// A change to pages done: the change taking it back, the page to show, and pages gone. |
| ... | ... | @@ -375,7 +377,7 @@ impl Site { |
| 375 | 377 | } |
| 376 | 378 | |
| 377 | 379 | /// The page shown once `gone` leave `listed`, preferring `prefer`, and the page `ops` gain |
| 378 | | /// where none stays. |
| 380 | /// where none stays; in the recycle bin, which gains none, a page gone. |
| 379 | 381 | fn after( |
| 380 | 382 | &self, |
| 381 | 383 | listed: &[(ExGuid, String, u32)], |
| ... | ... | @@ -383,13 +385,13 @@ impl Site { |
| 383 | 385 | prefer: Option<ExGuid>, |
| 384 | 386 | ops: &mut Vec<Op>, |
| 385 | 387 | ) -> (ExGuid, Option<ExGuid>) { |
| 386 | | match neighbor(listed, gone, prefer) { |
| 387 | | Some(show) => (show, None), |
| 388 | | None => { |
| 389 | | let space = self.fresh.space(); |
| 390 | | ops.push(Op::Section(SectionOp::Create(self.fresh.clone()))); |
| 391 | | (space, Some(space)) |
| 388 | match (neighbor(listed, gone, prefer), &self.fresh) { |
| 389 | (Some(show), _) => (show, None), |
| 390 | (None, Some(fresh)) => { |
| 391 | ops.push(Op::Section(SectionOp::Create(fresh.clone()))); |
| 392 | (fresh.space(), Some(fresh.space())) |
| 392 | 393 | } |
| 394 | (None, None) => (gone[0], None), |
| 393 | 395 | } |
| 394 | 396 | } |
| 395 | 397 | |
| ... | ... | @@ -1137,18 +1139,20 @@ impl State { |
| 1137 | 1139 | library: Arc::clone(&session.library), |
| 1138 | 1140 | held, |
| 1139 | 1141 | author: self.author.clone(), |
| 1140 | | fresh: self.dated_page(None, "")?, |
| 1142 | fresh: (!self.in_recycle_bin()) |
| 1143 | .then(|| self.dated_page(None, "")) |
| 1144 | .transpose()?, |
| 1141 | 1145 | }; |
| 1142 | 1146 | let shown = self.pane.showing.space; |
| 1143 | 1147 | let original = Arc::clone(&site.library); |
| 1144 | | let proxy = self.proxy.clone(); |
| 1148 | let (proxy, held) = (self.proxy.clone(), self.held(&original.location)); |
| 1145 | 1149 | self.undo.busy += 1; |
| 1146 | 1150 | self.pane.switching = Some((None, web_time::Instant::now())); |
| 1147 | 1151 | self.load_async(move || async move { |
| 1148 | 1152 | let applied = site.change(change, shown).await; |
| 1149 | | let show = match &applied { |
| 1150 | | Ok(Some(applied)) => applied.show, |
| 1151 | | _ => shown, |
| 1153 | let (show, emptied) = match &applied { |
| 1154 | Ok(Some(applied)) => (applied.show, applied.gone.contains(&applied.show)), |
| 1155 | _ => (shown, false), |
| 1152 | 1156 | }; |
| 1153 | 1157 | let failed = applied.as_ref().err().map(ToString::to_string); |
| 1154 | 1158 | let (stale, applied) = (failed.is_none(), applied.ok().flatten()); |
| ... | ... | @@ -1211,6 +1215,10 @@ impl State { |
| 1211 | 1215 | if let Some(failed) = failed { |
| 1212 | 1216 | return Err(failed.into()); |
| 1213 | 1217 | } |
| 1218 | if emptied { |
| 1219 | return crate::recycle::notebook_shown(Arc::clone(&site.library), proxy, &held) |
| 1220 | .await; |
| 1221 | } |
| 1214 | 1222 | Ok(Loaded::Page(show, site.replica.page(show)?)) |
| 1215 | 1223 | }); |
| 1216 | 1224 | Ok(()) |
| ... | ... | @@ -1489,7 +1497,7 @@ mod tests { |
| 1489 | 1497 | library: Arc::clone(&self.library), |
| 1490 | 1498 | held: Vec::new(), |
| 1491 | 1499 | author: AUTHOR.into(), |
| 1492 | | fresh: dated(), |
| 1500 | fresh: Some(dated()), |
| 1493 | 1501 | } |
| 1494 | 1502 | } |
| 1495 | 1503 | |
| ... | ... | @@ -1752,6 +1760,22 @@ mod tests { |
| 1752 | 1760 | assert_eq!(fixture.titles(), titled(&["First", "Third"])); |
| 1753 | 1761 | } |
| 1754 | 1762 | |
| 1763 | /// The last page sent out of a section of the recycle bin leaves it without pages, as |
| 1764 | /// OneNote leaves its Deleted Pages, where another section gains a dated one. |
| 1765 | #[test] |
| 1766 | fn the_last_page_sent_out_of_the_recycle_bin_leaves_none_behind() { |
| 1767 | let fixture = Fixture::new("send-binned", &["Only"]); |
| 1768 | let target = fixture.library.section_identity("B.one").unwrap(); |
| 1769 | let page = fixture.space("Only"); |
| 1770 | let mut site = fixture.site(); |
| 1771 | site.fresh = None; |
| 1772 | let sent = pollster::block_on(site.change(Change::Send { page, target }, page)) |
| 1773 | .unwrap() |
| 1774 | .unwrap(); |
| 1775 | assert_eq!((sent.show, sent.gone), (page, vec![page])); |
| 1776 | assert!(fixture.titles().is_empty()); |
| 1777 | } |
| 1778 | |
| 1755 | 1779 | /// A page edited while it is on its way to another section stays, with the edit, beside |
| 1756 | 1780 | /// the copy that arrived there, with nothing for Undo to take back; an edit to another page |
| 1757 | 1781 | /// meanwhile lets it go. Both hold once each section is opened again. |