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 {...@@ -165,16 +165,7 @@ impl State {
165 } {165 } {
166 return Ok(Loaded::Page(show, replica.page(show)?));166 return Ok(Loaded::Page(show, replica.page(show)?));
167 }167 }
168 // A section without pages shows no tab: the notebook shows instead.168 notebook_shown(library, proxy, &held).await
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))
178 });169 });
179 Ok(())170 Ok(())
180 }171 }
...@@ -213,6 +204,24 @@ impl State {...@@ -213,6 +204,24 @@ impl State {
213 }204 }
214}205}
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
216/// Does `request` to the bin's section `replica` holds, in `library`, as `author`: a page225/// Does `request` to the bin's section `replica` holds, in `library`, as `author`: a page
217/// restored goes to its section as one op, keeping its identity, a copy under a new one, and226/// restored goes to its section as one op, keeping its identity, a copy under a new one, and
218/// what leaves the bin goes from it as another. A section a pane shows is reached through227/// 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 {...@@ -349,7 +349,9 @@ struct Site {
349 /// path.349 /// path.
350 held: Vec<(String, Arc<Replica>)>,350 held: Vec<(String, Arc<Replica>)>,
351 author: String,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}
354356
355/// A change to pages done: the change taking it back, the page to show, and pages gone.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,7 +377,7 @@ impl Site {
375 }377 }
376378
377 /// The page shown once `gone` leave `listed`, preferring `prefer`, and the page `ops` gain379 /// 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 fn after(381 fn after(
380 &self,382 &self,
381 listed: &[(ExGuid, String, u32)],383 listed: &[(ExGuid, String, u32)],
...@@ -383,13 +385,13 @@ impl Site {...@@ -383,13 +385,13 @@ impl Site {
383 prefer: Option<ExGuid>,385 prefer: Option<ExGuid>,
384 ops: &mut Vec<Op>,386 ops: &mut Vec<Op>,
385 ) -> (ExGuid, Option<ExGuid>) {387 ) -> (ExGuid, Option<ExGuid>) {
386 match neighbor(listed, gone, prefer) {388 match (neighbor(listed, gone, prefer), &self.fresh) {
387 Some(show) => (show, None),389 (Some(show), _) => (show, None),
388 None => {390 (None, Some(fresh)) => {
389 let space = self.fresh.space();391 ops.push(Op::Section(SectionOp::Create(fresh.clone())));
390 ops.push(Op::Section(SectionOp::Create(self.fresh.clone())));392 (fresh.space(), Some(fresh.space()))
391 (space, Some(space))
392 }393 }
394 (None, None) => (gone[0], None),
393 }395 }
394 }396 }
395397
...@@ -1137,18 +1139,20 @@ impl State {...@@ -1137,18 +1139,20 @@ impl State {
1137 library: Arc::clone(&session.library),1139 library: Arc::clone(&session.library),
1138 held,1140 held,
1139 author: self.author.clone(),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 let shown = self.pane.showing.space;1146 let shown = self.pane.showing.space;
1143 let original = Arc::clone(&site.library);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 self.undo.busy += 1;1149 self.undo.busy += 1;
1146 self.pane.switching = Some((None, web_time::Instant::now()));1150 self.pane.switching = Some((None, web_time::Instant::now()));
1147 self.load_async(move || async move {1151 self.load_async(move || async move {
1148 let applied = site.change(change, shown).await;1152 let applied = site.change(change, shown).await;
1149 let show = match &applied {1153 let (show, emptied) = match &applied {
1150 Ok(Some(applied)) => applied.show,1154 Ok(Some(applied)) => (applied.show, applied.gone.contains(&applied.show)),
1151 _ => shown,1155 _ => (shown, false),
1152 };1156 };
1153 let failed = applied.as_ref().err().map(ToString::to_string);1157 let failed = applied.as_ref().err().map(ToString::to_string);
1154 let (stale, applied) = (failed.is_none(), applied.ok().flatten());1158 let (stale, applied) = (failed.is_none(), applied.ok().flatten());
...@@ -1211,6 +1215,10 @@ impl State {...@@ -1211,6 +1215,10 @@ impl State {
1211 if let Some(failed) = failed {1215 if let Some(failed) = failed {
1212 return Err(failed.into());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 Ok(Loaded::Page(show, site.replica.page(show)?))1222 Ok(Loaded::Page(show, site.replica.page(show)?))
1215 });1223 });
1216 Ok(())1224 Ok(())
...@@ -1489,7 +1497,7 @@ mod tests {...@@ -1489,7 +1497,7 @@ mod tests {
1489 library: Arc::clone(&self.library),1497 library: Arc::clone(&self.library),
1490 held: Vec::new(),1498 held: Vec::new(),
1491 author: AUTHOR.into(),1499 author: AUTHOR.into(),
1492 fresh: dated(),1500 fresh: Some(dated()),
1493 }1501 }
1494 }1502 }
14951503
...@@ -1752,6 +1760,22 @@ mod tests {...@@ -1752,6 +1760,22 @@ mod tests {
1752 assert_eq!(fixture.titles(), titled(&["First", "Third"]));1760 assert_eq!(fixture.titles(), titled(&["First", "Third"]));
1753 }1761 }
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
1755 /// A page edited while it is on its way to another section stays, with the edit, beside1779 /// A page edited while it is on its way to another section stays, with the edit, beside
1756 /// the copy that arrived there, with nothing for Undo to take back; an edit to another page1780 /// the copy that arrived there, with nothing for Undo to take back; an edit to another page
1757 /// meanwhile lets it go. Both hold once each section is opened again.1781 /// meanwhile lets it go. Both hold once each section is opened again.