notes editor over the vault (Obsidian-compatible)
git clone https://git.lucas.co/cce-notes.git
refactor: hold widgets in Owned boxes (cce-ui Owned<W>)
The UiContext registry keeps raw pointers to registered widgets, and a
widget that moved while registered (its Vec reallocating, its struct
returned by value) left one pointing at the old address. Each widget
field is now an Owned<Adapted<..>> — a heap box whose allocation, not the
widget, carries the liveness token the registry watches — so the
registered address never moves and is dropped from the registry when the
box is freed. Field access is unchanged through Deref; construction
sites wrap in Owned::new.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
src/main.rs | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index 2094739..dde7822 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -33,6 +33,7 @@ use std::path::{Path, PathBuf};
use std::sync::OnceLock;
use std::time::{Duration, Instant};
+use cce_ui::widget::Owned;
use cce_ui::engine::{Application, CursorIcon, EngineState, LogicalPosition, LogicalSize, WindowSettings};
use cce_ui::scene::layout::Rect;
use cce_ui::scene::paint::{DisplayList, PaintCtx};
@@ -234,10 +235,10 @@ struct NotesApp {
hist_pos: usize,
switcher: Option<Switcher>,
- switcher_input: Adapted<TextBox>,
+ switcher_input: Owned<Adapted<TextBox>>,
left_tab: LeftTab,
- search_input: Adapted<TextBox>,
+ search_input: Owned<Adapted<TextBox>>,
search_panel: Panel,
/// The query the search panel shows results for.
search_seen: String,
@@ -1634,9 +1635,9 @@ impl Application for NotesApp {
history: Vec::new(),
hist_pos: 0,
switcher: None,
- switcher_input,
+ switcher_input: Owned::new(switcher_input),
left_tab: LeftTab::Files,
- search_input,
+ search_input: Owned::new(search_input),
search_panel: Panel::default(),
search_seen: String::new(),
show_side: true,