authoravatarclover caruso<git@paperclover.net>2026-10-19 16:24:37-07:00
committeravatarclover caruso<git@paperclover.net>2026-10-19 22:58:56-07:00
log4dba5df3e540c8f1091f6b99dc53c997dea40f7a
tree484accaf8f3a14e735446747599ccaabcee06928
parent2f91a95387b710cc973f6ae8facbecca45b8a499
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

fix(desktop): leave Deleted Pages empty when its last page is dragged out

A page dragged from a section of the Recycle Bin to another left a dated blank page behind, as an ordinary section gains one. OneNote leaves Deleted Pages empty (corpus/recycle-purge), as the bin's Restore To already did; the bin's emptied section now gives way to the notebook's first section. - Dragging the last page out of a Recycle Bin section no longer leaves a blank page there. Assisted-by: claude-opus-5.5

2 files changed, 57 insertions(+), 24 deletions(-)

crates/snowbound/src/recycle.rs+19-10
......@@ -165,16 +165,7 @@ impl State {
165165 } {
166166 return Ok(Loaded::Page(show, replica.page(show)?));
167167 }
168 // A section without pages shows no tab: the notebook shows instead.
169 let path = library
170 .first_section()
171 .ok_or("The notebook has no sections")?;
172 if let Some((_, replica)) = held.iter().find(|(held, _)| *held == path) {
173 return crate::split::held_page(library, path, replica, None);
174 }
175 let section = library.open_async(&path, notify(proxy)).await?;
176 let (session, space, page) = read_session(section, library, path, None)?;
177 Ok(Loaded::Section(Box::new(session), space, page))
168 notebook_shown(library, proxy, &held).await
178169 });
179170 Ok(())
180171 }
......@@ -213,6 +204,24 @@ impl State {
213204 }
214205}
215206
207/// The notebook's first section, shown in place of a section of the bin left without pages,
208/// which shows no tab; through its replica in `held` where a parked pane holds it.
209pub(crate) async fn notebook_shown(
210 library: Arc<Library>,
211 proxy: crate::EventLoopProxy<crate::UserEvent>,
212 held: &[(String, Arc<notebook::Replica>)],
213) -> Result<Loaded, Box<dyn Error>> {
214 let path = library
215 .first_section()
216 .ok_or("The notebook has no sections")?;
217 if let Some((_, replica)) = held.iter().find(|(held, _)| *held == path) {
218 return crate::split::held_page(library, path, replica, None);
219 }
220 let section = library.open_async(&path, notify(proxy)).await?;
221 let (session, space, page) = read_session(section, library, path, None)?;
222 Ok(Loaded::Section(Box::new(session), space, page))
223}
224
216225/// Does `request` to the bin's section `replica` holds, in `library`, as `author`: a page
217226/// restored goes to its section as one op, keeping its identity, a copy under a new one, and
218227/// what leaves the bin goes from it as another. A section a pane shows is reached through
crates/snowbound/src/undo.rs+38-14
......@@ -349,7 +349,9 @@ struct Site {
349349 /// path.
350350 held: Vec<(String, Arc<Replica>)>,
351351 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>,
353355}
354356
355357/// A change to pages done: the change taking it back, the page to show, and pages gone.
......@@ -375,7 +377,7 @@ impl Site {
375377 }
376378
377379 /// 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.
379381 fn after(
380382 &self,
381383 listed: &[(ExGuid, String, u32)],
......@@ -383,13 +385,13 @@ impl Site {
383385 prefer: Option<ExGuid>,
384386 ops: &mut Vec<Op>,
385387 ) -> (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()))
392393 }
394 (None, None) => (gone[0], None),
393395 }
394396 }
395397
......@@ -1137,18 +1139,20 @@ impl State {
11371139 library: Arc::clone(&session.library),
11381140 held,
11391141 author: self.author.clone(),
1140 fresh: self.dated_page(None, "")?,
1142 fresh: (!self.in_recycle_bin())
1143 .then(|| self.dated_page(None, ""))
1144 .transpose()?,
11411145 };
11421146 let shown = self.pane.showing.space;
11431147 let original = Arc::clone(&site.library);
1144 let proxy = self.proxy.clone();
1148 let (proxy, held) = (self.proxy.clone(), self.held(&original.location));
11451149 self.undo.busy += 1;
11461150 self.pane.switching = Some((None, web_time::Instant::now()));
11471151 self.load_async(move || async move {
11481152 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),
11521156 };
11531157 let failed = applied.as_ref().err().map(ToString::to_string);
11541158 let (stale, applied) = (failed.is_none(), applied.ok().flatten());
......@@ -1211,6 +1215,10 @@ impl State {
12111215 if let Some(failed) = failed {
12121216 return Err(failed.into());
12131217 }
1218 if emptied {
1219 return crate::recycle::notebook_shown(Arc::clone(&site.library), proxy, &held)
1220 .await;
1221 }
12141222 Ok(Loaded::Page(show, site.replica.page(show)?))
12151223 });
12161224 Ok(())
......@@ -1489,7 +1497,7 @@ mod tests {
14891497 library: Arc::clone(&self.library),
14901498 held: Vec::new(),
14911499 author: AUTHOR.into(),
1492 fresh: dated(),
1500 fresh: Some(dated()),
14931501 }
14941502 }
14951503
......@@ -1752,6 +1760,22 @@ mod tests {
17521760 assert_eq!(fixture.titles(), titled(&["First", "Third"]));
17531761 }
17541762
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
17551779 /// A page edited while it is on its way to another section stays, with the edit, beside
17561780 /// the copy that arrived there, with nothing for Undo to take back; an edit to another page
17571781 /// meanwhile lets it go. Both hold once each section is opened again.