Repository navigation
Keep NoteCraft’s File screen responsive to hover and touch #739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3136,17 +3136,19 @@ impl NoteCraftApp { | |
| /// made it (`Ok(None)` until then). `Err` when the chosen place is no longer a section. | ||
| fn quick_notes_section(&self) -> Result<Option<PathBuf>, ()> { | ||
| match self.session.settings.get(QUICK_NOTES_KEY).filter(|p| !p.trim().is_empty()) { | ||
| Some(chosen) => match self.session.resolve(chosen.trim()) { | ||
| Ok(path) if notecraft_store::tree::read_node(&path).is_some_and(|n| n.kind == NodeKind::Section) => Ok(Some(path)), | ||
| _ => Err(()), | ||
| }, | ||
| Some(chosen) => self.configured_quick_notes_section(&chosen).map(Some).ok_or(()), | ||
| None => { | ||
| let section = self.session.root().join("quick-notes").join("quick-notes"); | ||
| Ok(notecraft_store::tree::read_node(§ion).is_some_and(|n| n.kind == NodeKind::Section).then_some(section)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn configured_quick_notes_section(&self, chosen: &str) -> Option<PathBuf> { | ||
| let path = self.session.resolve(chosen.trim()).ok()?; | ||
| notecraft_store::tree::read_node(&path).is_some_and(|node| node.kind == NodeKind::Section).then_some(path) | ||
| } | ||
|
|
||
| /// What File > Options shows about Quick Notes (issue #567). | ||
| fn quick_notes_choice(&self) -> backstage::QuickNotes { | ||
| let tree = self.session.tree(); | ||
|
|
@@ -3165,11 +3167,9 @@ impl NoteCraftApp { | |
| } | ||
| } | ||
| let chosen = self.session.settings.get(QUICK_NOTES_KEY).filter(|p| !p.trim().is_empty()); | ||
| let (chosen, broken) = match (chosen, self.quick_notes_section()) { | ||
| (None, _) => (None, false), | ||
| (Some(_), Ok(path)) => (path, false), | ||
| (Some(_), Err(())) => (None, true), | ||
| }; | ||
| let configured = chosen.as_deref().and_then(|path| self.configured_quick_notes_section(path)); | ||
| let broken = chosen.is_some() && configured.is_none(); | ||
| let chosen = configured; | ||
| backstage::QuickNotes { chosen_place: chosen.as_deref().map(place).unwrap_or_default(), chosen, broken, sections } | ||
| } | ||
|
|
||
|
|
@@ -3496,10 +3496,19 @@ impl NoteCraftApp { | |
| && !self.space_tool | ||
| && matches!(self.pointer, ribbon::Pointer::Draw | ribbon::Pointer::Erase | ribbon::Pointer::Lasso | ribbon::Pointer::Shape(_)) | ||
| && self.editor.as_ref().is_some_and(|ed| ed.writable && !ed.locked); | ||
| let on_page = | ||
| |at| page.is_some_and(|page| page.contains(at)) && ctx.layer_id_at(at).is_none_or(|layer| layer.order < egui::Order::Foreground); | ||
| let unobscured = |at| ctx.layer_id_at(at).is_none_or(|layer| layer.order < egui::Order::Foreground); | ||
| let on_page = |at| page.is_some_and(|page| page.contains(at)) && unobscured(at); | ||
| let on_text = |at| type_tap && self.ink_text_targets.iter().any(|rect| rect.contains(at)); | ||
| let tap = self.touch.route(&mut raw.events, time, |at| if on_page(at) { (drag, on_text(at)) } else { (crate::touch::Drag::Pointer, false) }); | ||
| let file = self.backstage.is_some() && self.dialog.is_none(); | ||
| let tap = self.touch.route(&mut raw.events, time, |at| { | ||
| if on_page(at) { | ||
| (drag, on_text(at)) | ||
| } else if file && unobscured(at) && backstage::scrolls_at(ctx, at) { | ||
| (crate::touch::Drag::PanOrClick, false) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve momentum when routing File swipes. If a user flicks Options and lifts the finger, this path stops scrolling immediately. The canvas compensates through
|
||
| } else { | ||
| (crate::touch::Drag::Pointer, false) | ||
| } | ||
| }); | ||
| self.ink_text_tap = tap.filter(|&at| on_page(at) && on_text(at)); | ||
| // A finger held still turns into a mouse after a while: a frame is asked for then, as | ||
| // nothing else may come to wake the window. | ||
|
|
@@ -7136,19 +7145,23 @@ impl NoteCraftApp { | |
| } | ||
| } | ||
| let tokens = self.tokens; | ||
| let quick_notes = self.quick_notes_choice(); | ||
| // Each File page prepares only its own data. Reading recent notebook trees on | ||
| // every hover frame used to make even Settings wait on notebook storage. | ||
| let options = page == "Options"; | ||
| let quick_notes = if options { self.quick_notes_choice() } else { backstage::QuickNotes::default() }; | ||
| let folder = self.shown(self.session.root()); | ||
| let recent = self.recent_notebooks(); | ||
| let recent = if page == "Open" { self.recent_notebooks() } else { Vec::new() }; | ||
| let (root, redact) = (self.session.root().to_path_buf(), self.redact_paths); | ||
| let show_path = move |p: &Path| shown_in(&root, p, redact); | ||
| let ui_language = self.ui_language.clone(); | ||
| let languages = crate::i18n::available_languages(); | ||
| let languages = if options { crate::i18n::available_languages() } else { Vec::new() }; | ||
| let about_or_options = options || page == "About"; | ||
| let mut acts = Vec::new(); | ||
| egui::CentralPanel::default().show(ui, |ui| { | ||
| let telemetry_root = self.session.settings.path().parent().unwrap_or(std::path::Path::new(".")).join("telemetry"); | ||
| let telemetry_level = self.session.settings.get("telemetry_level").unwrap_or_else(|| "none".into()); | ||
| let session_id = self.session.settings.get("telemetry_session_id"); | ||
| let update = self.update.lock().map(|s| s.clone()).unwrap_or_default(); | ||
| let telemetry_level = if options { self.session.settings.get("telemetry_level") } else { None }; | ||
| let session_id = if about_or_options { self.session.settings.get("telemetry_session_id") } else { None }; | ||
| let update = if about_or_options { self.update.lock().map(|s| s.clone()).unwrap_or_default() } else { crate::update::Status::default() }; | ||
| acts = backstage::show( | ||
| ui, | ||
| self.session.tree(), | ||
|
|
@@ -7157,7 +7170,7 @@ impl NoteCraftApp { | |
| page, | ||
| &show_path, | ||
| &telemetry_root, | ||
| &telemetry_level, | ||
| telemetry_level.as_deref().unwrap_or("none"), | ||
| session_id.as_deref(), | ||
| &ui_language, | ||
| &languages, | ||
|
|
@@ -7519,10 +7532,10 @@ impl NoteCraftApp { | |
| if !seen.insert(path.clone()) { | ||
| continue; | ||
| } | ||
| if let Some(notebook) = notecraft_store::tree::load_tree(&path) | ||
| && notebook.info.kind == NodeKind::Notebook | ||
| if let Some(info) = notecraft_store::tree::read_node(&path) | ||
| && info.kind == NodeKind::Notebook | ||
| { | ||
| recent.push(notebook); | ||
| recent.push(Node { path, info, children: Vec::new() }); | ||
| if recent.len() == 12 { | ||
| break; | ||
| } | ||
|
|
@@ -19774,6 +19787,25 @@ mod alert_tests { | |
| assert!(app.update_prompt.is_some(), "the shared update prompt is set up at start; it opens once GitHub answers"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn file_open_needs_only_recent_notebook_metadata() { | ||
| let tmp = notecraft_store::testing::TempDir::new("recent-notebook-metadata"); | ||
| let settings = notecraft_store::Settings::at(tmp.path().join("settings.toml")); | ||
| let mut session = Session::new(&tmp.path().join("notebooks"), settings).expect("session"); | ||
| let sample = notecraft_engine::sample::create_sample(&mut session, None).expect("sample"); | ||
| let notebook = node_at(session.tree(), &sample.notebook).expect("sample notebook"); | ||
| assert!(!notebook.children.is_empty(), "the fixture has a real notebook tree"); | ||
| let expected = notebook.info.clone(); | ||
| let mut app = NoteCraftApp::new(session); | ||
| app.remember_recent_notebook(&sample.notebook); | ||
|
|
||
| let recent = app.recent_notebooks(); | ||
|
|
||
| assert_eq!(recent.len(), 1); | ||
| assert_eq!(recent[0].info, expected); | ||
| assert!(recent[0].children.is_empty(), "the File list only needs the notebook header"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn after_a_change_the_window_lists_the_notebooks_in_the_new_folder() { | ||
| let t = notecraft_store::testing::TempDir::new("notebooks-folder-list"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File scrolling takes finger drags over floating windows.
When the Theme window is open over File content, a finger on the window can start a File pan. The File branch accepts any layer below
Order::Foreground, and the Theme window uses the defaultOrder::Middle. The router withholds the press and sends the travel as scroll input, so the window cannot be moved by touch. Before this change, these touches usedPointer. Floating windows keep their pointer routing. For example, check that the layer under the touch is the File content layer before the File branch admits it.