authoravatarclover caruso<git@paperclover.net>2026-10-19 17:06:15-07:00
committeravatarclover caruso<git@paperclover.net>2026-10-19 22:58:56-07:00
log29745d45b154e4fdf378bd73d297e5b657c23c5b
tree32be5c3ef4416303d7931a6ea02b23b98075f118
parent73a0686b3eb03e75b195af5554057fd8a3426f51
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

fix: Enter takes the default button of every dialog, which says it is the default

Save As and Print passed no focus to the key handling that takes Enter, so Enter did nothing in them; Properties, Options, Link, the tag editor, Customize Tags, Connect to Server, password protection and Unpack took it only from a field, so not while the dialog itself held the focus, as it does when it opens. Each now takes Enter from the dialog as well. Customize Tags, which took no Enter at all, takes it once a change makes OK available. The default button is now exposed to assistive technology as the default button. Escape already closed every dialog. Replays now test Enter and Escape in Save As and Export as PDF, through a replay answer for the save panel the same as the one #77 adds. - Enter now chooses the default button in Save As, Print, Export as PDF and every other dialog. Assisted-by: claude-opus-5.5

16 files changed, 124 insertions(+), 14 deletions(-)

crates/snowbound/src/link.rs+2-2
......@@ -100,9 +100,9 @@ impl State {
100100 }
101101 let theme = ui.theme.clone();
102102 let row = theme.font_size * 2.0;
103 let fields = [text_field(), address_field(), search_field()];
103 let owners = [id(), text_field(), address_field()];
104104 let entered =
105 ui::popup::navigation(ui, &fields[..2], &[NamedKey::Enter]).contains(&NamedKey::Enter);
105 ui::popup::navigation(ui, &owners, &[NamedKey::Enter]).contains(&NamedKey::Enter);
106106 ui.open_as(
107107 id(),
108108 Spec {
crates/snowbound/src/linux.rs+3
......@@ -1693,6 +1693,9 @@ pub fn pick_new(
16931693 folder: Option<&std::path::Path>,
16941694 reply: Reply<PathBuf>,
16951695) {
1696 if let Some(path) = crate::replayed_answer() {
1697 return reply.send(path);
1698 }
16961699 use std::os::unix::ffi::OsStrExt;
16971700 let mut options = HashMap::from([
16981701 ("current_name", Value::from(name.to_owned())),
crates/snowbound/src/macos.rs+3
......@@ -888,6 +888,9 @@ pub fn pick_new(
888888 folder: Option<&std::path::Path>,
889889 reply: Reply<std::path::PathBuf>,
890890) {
891 if let Some(path) = crate::replayed_answer() {
892 return reply.send(path);
893 }
891894 let mtm = MainThreadMarker::new().expect("Panels belong to the main thread");
892895 unsafe {
893896 let panel = NSSavePanel::savePanel(mtm);
crates/snowbound/src/main.rs+23
......@@ -432,6 +432,9 @@ enum Replay {
432432 ClosePane,
433433 /// Writes the settings as they would be saved, as a screenshot's replay saves none.
434434 Settings(PathBuf),
435 /// What the next save panel answers, in place of showing itself.
436 #[cfg(not(target_arch = "wasm32"))]
437 Answer(PathBuf),
435438 Quit,
436439}
437440
......@@ -452,6 +455,19 @@ fn automated() -> bool {
452455 AUTOMATED.load(Ordering::Relaxed)
453456}
454457
458/// What a replay told the next save panel to answer.
459#[cfg(not(target_arch = "wasm32"))]
460static ANSWER: Mutex<Option<PathBuf>> = Mutex::new(None);
461
462/// The answer a replay gave the save panel about to show, taken.
463#[cfg(not(target_arch = "wasm32"))]
464fn replayed_answer() -> Option<PathBuf> {
465 ANSWER
466 .lock()
467 .unwrap_or_else(std::sync::PoisonError::into_inner)
468 .take()
469}
470
455471/// With `SNOWBOUND_PROFILE` set, prints how long a phase of the frame took since `start`.
456472fn lap(phase: &str, start: Instant) {
457473 static PROFILE: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
......@@ -6775,6 +6791,12 @@ impl State {
67756791 eprintln!("{error}");
67766792 }
67776793 }
6794 #[cfg(not(target_arch = "wasm32"))]
6795 Replay::Answer(path) => {
6796 *ANSWER
6797 .lock()
6798 .unwrap_or_else(std::sync::PoisonError::into_inner) = Some(path)
6799 }
67786800 }
67796801 // A covered window gets no redraws, so each step draws its own frame.
67806802 if let Err(error) = self.frame() {
......@@ -7272,6 +7294,7 @@ fn replay(script: String, proxy: EventLoopProxy<UserEvent>) -> Result<(), Box<dy
72727294 ))),
72737295 "wait" => Err(std::time::Duration::from_millis(rest.parse()?)),
72747296 "quit" => Ok(Replay::Quit),
7297 "answer" => Ok(Replay::Answer(rest.into())),
72757298 "resize" => Ok(Replay::Resize(
72767299 numbers()?
72777300 .try_into()
crates/snowbound/src/options.rs+1-1
......@@ -425,7 +425,7 @@ impl State {
425425 let row = row_height(&theme);
426426 let ui = &mut self.ui;
427427 let column = labels_column(ui);
428 let entered = ui::popup::navigation(ui, &[user_name()], &[NamedKey::Enter])
428 let entered = ui::popup::navigation(ui, &[id(), user_name()], &[NamedKey::Enter])
429429 .contains(&NamedKey::Enter);
430430 // As tall as its contents up to the window, which the list then scrolls within.
431431 let loose = Extent {
crates/snowbound/src/print.rs+2-1
......@@ -169,7 +169,8 @@ impl State {
169169 session.tabs[session.tab].name.clone()
170170 });
171171 let theme = ui.theme.clone();
172 let entered = ui::popup::navigation(ui, &[], &[NamedKey::Enter]).contains(&NamedKey::Enter);
172 let entered =
173 ui::popup::navigation(ui, &[id()], &[NamedKey::Enter]).contains(&NamedKey::Enter);
173174 let title = if dialog.export {
174175 "Export as PDF"
175176 } else {
crates/snowbound/src/properties.rs+1-1
......@@ -58,7 +58,7 @@ impl State {
5858 }
5959 let theme = ui.theme.clone();
6060 let row = theme.font_size * 2.0;
61 let entered = ui::popup::navigation(ui, &[name_field()], &[NamedKey::Enter])
61 let entered = ui::popup::navigation(ui, &[id(), name_field()], &[NamedKey::Enter])
6262 .contains(&NamedKey::Enter);
6363 ui.open_as(
6464 id(),
crates/snowbound/src/protection.rs+2-1
......@@ -388,7 +388,8 @@ impl State {
388388 ui.set_focus(Some(field(0)));
389389 }
390390 let entered =
391 ui::popup::navigation(ui, &owners, &[NamedKey::Enter]).contains(&NamedKey::Enter);
391 ui::popup::navigation(ui, &[&[id()], &owners[..]].concat(), &[NamedKey::Enter])
392 .contains(&NamedKey::Enter);
392393 let protected = asking.library.protected(&asking.path);
393394 let title = match asking.dialog {
394395 Dialog::Unlock(..) => "Protected Section",
crates/snowbound/src/save_as.rs+2-1
......@@ -85,7 +85,8 @@ impl State {
8585 }
8686 let theme = ui.theme.clone();
8787 let row = theme.font_size * 2.0;
88 let entered = ui::popup::navigation(ui, &[], &[NamedKey::Enter]).contains(&NamedKey::Enter);
88 let entered =
89 ui::popup::navigation(ui, &[id()], &[NamedKey::Enter]).contains(&NamedKey::Enter);
8990 ui.open_as(
9091 id(),
9192 Spec {
crates/snowbound/src/server.rs+2-1
......@@ -586,8 +586,9 @@ impl State {
586586 Step::SignIn => &[user_field(), password_field(), domain_field()],
587587 Step::Browse => &[],
588588 };
589 let owners: Vec<Id> = [id()].into_iter().chain(fields.iter().copied()).collect();
589590 let entered =
590 ui::popup::navigation(ui, fields, &[NamedKey::Enter]).contains(&NamedKey::Enter);
591 ui::popup::navigation(ui, &owners, &[NamedKey::Enter]).contains(&NamedKey::Enter);
591592 ui.open_as(
592593 id(),
593594 Spec {
crates/snowbound/src/tags.rs+7-3
......@@ -402,6 +402,8 @@ impl State {
402402 return;
403403 }
404404 let theme = ui.theme.clone();
405 let entered =
406 ui::popup::navigation(ui, &[id()], &[NamedKey::Enter]).contains(&NamedKey::Enter);
405407 dialog(ui, id(), "Customize Tags", WIDTH);
406408 ui.leaf(
407409 "all",
......@@ -525,7 +527,9 @@ impl State {
525527 });
526528 ui.close();
527529 crate::buttons(ui);
528 let [cancel, ok] = ui::dialog_buttons(ui, "OK", list.tags != self.tags);
530 let changed = list.tags != self.tags;
531 let [cancel, ok] = ui::dialog_buttons(ui, "OK", changed);
532 let ok = ok || entered && changed;
529533 ui.close();
530534 if let Some(place) = list.selected {
531535 if up {
......@@ -657,8 +661,8 @@ fn tag_editor(
657661 }
658662 let (tag, place) = editor.as_mut()?;
659663 let theme = ui.theme.clone();
660 let entered =
661 ui::popup::navigation(ui, &[name_field()], &[NamedKey::Enter]).contains(&NamedKey::Enter);
664 let entered = ui::popup::navigation(ui, &[editor_id(), name_field()], &[NamedKey::Enter])
665 .contains(&NamedKey::Enter);
662666 let title = if place.is_some() {
663667 "Modify Tag"
664668 } else {
crates/snowbound/src/unpack.rs+1-1
......@@ -63,7 +63,7 @@ impl State {
6363 }
6464 let theme = ui.theme.clone();
6565 let row = theme.font_size * 2.0;
66 let entered = ui::popup::navigation(ui, &[name_field()], &[NamedKey::Enter])
66 let entered = ui::popup::navigation(ui, &[id(), name_field()], &[NamedKey::Enter])
6767 .contains(&NamedKey::Enter);
6868 ui.open_as(
6969 id(),
crates/snowbound/src/windows.rs+3
......@@ -1710,6 +1710,9 @@ pub fn pick_new(
17101710 folder: Option<&std::path::Path>,
17111711 reply: Reply<PathBuf>,
17121712) {
1713 if let Some(path) = crate::replayed_answer() {
1714 return reply.send(path);
1715 }
17131716 pick(
17141717 title,
17151718 &[("All files", "*.*")],
crates/snowbound/tests/replay.rs+70
......@@ -1793,6 +1793,76 @@ fn closing_split_panes_leaves_the_window_as_it_was() {
17931793 );
17941794}
17951795
1796/// Opens Save As with its chord.
1797const SAVE_AS: [&str; 5] = [
1798 "modifiers shift command",
1799 "key s",
1800 "modifiers",
1801 "settle",
1802 "wait 300",
1803];
1804
1805/// Enter takes a dialog's default button, which assistive technology is told is the default:
1806/// Save As saves the page where the save panel answers, and Export as PDF writes the PDF.
1807#[test]
1808fn enter_takes_the_default_button_of_save_as_and_export_as_pdf() {
1809 let scratch = Scratch::new("dialog-enter");
1810 let notebook =
1811 Path::new(env!("CARGO_MANIFEST_DIR")).join("../../corpus/cross-container/candidate");
1812 let (saved, pdf) = (scratch.0.join("Saved.one"), scratch.0.join("Exported.pdf"));
1813 let answer_saved = format!("answer {}", saved.display());
1814 let answer_pdf = format!("answer {}", pdf.display());
1815 let mut steps: Vec<&str> = SAVE_AS.to_vec();
1816 steps.extend([
1817 "accessibility save-as",
1818 &answer_saved,
1819 "key Enter",
1820 "settle",
1821 "modifiers shift command",
1822 "key p",
1823 "modifiers",
1824 "settle",
1825 "type Export as PDF",
1826 "settle",
1827 "key Enter",
1828 "settle",
1829 "wait 300",
1830 "accessibility export",
1831 &answer_pdf,
1832 "key Enter",
1833 "settle",
1834 "accessibility after",
1835 ]);
1836 let [save_as, export, after] = replay(&scratch, Some(&notebook), &steps)
1837 .try_into()
1838 .unwrap();
1839 assert!(save_as.contains(r#"DefaultButton "Save As""#), "{save_as}");
1840 assert!(export.contains(r#"DefaultButton "Export""#), "{export}");
1841 assert!(!after.contains("Dialog"), "{after}");
1842 assert!(std::fs::metadata(&saved).is_ok_and(|file| file.len() > 0));
1843 assert!(std::fs::read(&pdf).is_ok_and(|bytes| bytes.starts_with(b"%PDF")));
1844}
1845
1846/// Escape closes a dialog without doing what it offers.
1847#[test]
1848fn escape_closes_save_as() {
1849 let scratch = Scratch::new("dialog-escape");
1850 let notebook =
1851 Path::new(env!("CARGO_MANIFEST_DIR")).join("../../corpus/cross-container/candidate");
1852 let mut steps: Vec<&str> = SAVE_AS.to_vec();
1853 steps.extend([
1854 "accessibility open",
1855 "key Escape",
1856 "settle",
1857 "accessibility closed",
1858 ]);
1859 let [open, closed] = replay(&scratch, Some(&notebook), &steps)
1860 .try_into()
1861 .unwrap();
1862 assert!(open.contains(r#"Dialog "Save As""#), "{open}");
1863 assert!(!closed.contains(r#"Dialog "Save As""#), "{closed}");
1864}
1865
17961866/// A layout of panes as the settings keep it, on pages of `notebook`'s sections: a pane on
17971867/// the first, then a part below it, the second above the third. A page of `None` is gone.
17981868fn layout(notebook: &Path, panes: [(&str, Option<&str>); 3]) -> serde_json::Value {
crates/ui/src/widgets.rs+1-1
......@@ -54,7 +54,7 @@ pub fn dialog_buttons(ui: &mut Ui, text: &str, enabled: bool) -> [bool; 2] {
5454 radius: 4.0,
5555 pad: [theme.font_size * 0.75, 0.0],
5656 center: true,
57 role: Some(Role::Button),
57 role: Some(Role::DefaultButton),
5858 ..Spec::default()
5959 };
6060 let clicked = ui.leaf("default", spec).clicked;
tools/canvas/README.md+1-1
......@@ -56,7 +56,7 @@ As in OneNote 2010, Notebook Recycle Bin (File menu, a notebook's context menu,
5656
5757The `ui` crate builds every frame from the application's state. A cache keyed by stable box ids keeps hover, press, focus, scroll and animation values, and the previous frame's layout routes the frame's input before building, so a frame answers input one layout late and paints with its own. Sizes are solved per axis after building: fixed, label-sized, a fraction of an ancestor, or the sum of children, with overflow shared out by each box's strictness. The page is a custom box: `ui` routes it the pointer, wheel, key and input-method events that land on it, in order, and the host hands them to `PageView` and paints the page in a clipped layer of the same frame. Page scrollbars are `ui` widgets over that box; the canvas reports only its scroll bounds. Text fields edit through `draw::edit`, as the page does, so keys, clicks and drags select and move the same way in both. Work the frame asks for (page requests, saving) runs after the frame is painted and requests the frame that shows it. Opening a section or page reads and lays it out on a thread of its own while the current page stays live; the newest replaces the page once the pictures it shows first are drawn, or after 200 ms. Its tab is selected at once, and an open that takes over 80 ms shows a page's outline in place of the page leaving, which takes no input. The pages beside the open one, the sections beside the open section and a hovered page or section tab are read ahead on a thread of their own. A notebook keeps the last three sections left or read ahead open, which `Library::open` hands out, and the last 32 pages shown or read ahead keep their scenes, with up to 128 MiB of decoded pictures, so a page shown again is laid out afresh around pictures already drawn.
5858
59A covered window receives no redraws, so interaction can be scripted: `SNOWBOUND_REPLAY` names a file of `move X Y`, `press [right]`, `release [right]`, `wheel DX DY`, `pinch FACTOR`, `key NAME`, `type TEXT`, `modifiers [shift] [command]`, `wait MS`, `snapshot PNG_PATH`, `accessibility TEXT_PATH` (the window's accessibility tree, a node a line, as the platform shows it), `appearance light|dark`, `resize WIDTH HEIGHT`, `renderer NAME` (switches as Options' Renderer does) and `quit` lines in logical pixels, and each step and every 16 ms of a wait draws a frame. With `--screenshot` as well, the window stays hidden and only the replay's snapshots capture it. Snapshots wait for the page's pictures, file icons and background art to finish rasterizing; `SNOWBOUND_FRAMES` frames never wait, so art appears in the first frame drawn after it is ready. Snapshots omit the window's traffic lights, which AppKit draws. Replays edit and save like a user, so point them at a copy of a notebook. Their edits carry the settings' user name, so give fixture runs a `--settings` file holding `{"user_name": "Snowbound Test"}`. A replay or `--screenshot` run never reads the account's own settings or iCloud: without `--settings` it starts from none, and its iCloud folder is only the one `SNOWBOUND_ICLOUD_FOLDER` names.
59A covered window receives no redraws, so interaction can be scripted: `SNOWBOUND_REPLAY` names a file of `move X Y`, `press [right]`, `release [right]`, `wheel DX DY`, `pinch FACTOR`, `key NAME`, `type TEXT`, `modifiers [shift] [command]`, `wait MS`, `snapshot PNG_PATH`, `accessibility TEXT_PATH` (the window's accessibility tree, a node a line, as the platform shows it), `appearance light|dark`, `resize WIDTH HEIGHT`, `renderer NAME` (switches as Options' Renderer does), `answer PATH` (what the next save panel answers, without showing) and `quit` lines in logical pixels, and each step and every 16 ms of a wait draws a frame. With `--screenshot` as well, the window stays hidden and only the replay's snapshots capture it. Snapshots wait for the page's pictures, file icons and background art to finish rasterizing; `SNOWBOUND_FRAMES` frames never wait, so art appears in the first frame drawn after it is ready. Snapshots omit the window's traffic lights, which AppKit draws. Replays edit and save like a user, so point them at a copy of a notebook. Their edits carry the settings' user name, so give fixture runs a `--settings` file holding `{"user_name": "Snowbound Test"}`. A replay or `--screenshot` run never reads the account's own settings or iCloud: without `--settings` it starts from none, and its iCloud folder is only the one `SNOWBOUND_ICLOUD_FOLDER` names.
6060
6161```sh
6262cp -RL SOURCE_NOTEBOOK /tmp/notebook-copy && chmod u+w /tmp/notebook-copy/*.one